Redirect to non-www and non-https in htaccess
Redirect to non-www and non-https in htaccess - If a page has internal and external outgoing links to redirecting URLs, it’s returning 3xx (301, 302, etc.) HTTP status codes standing for redirection. This issue means that the page does not exist on a permanent or temporary basis. It appears on most of the popular web browsers, usually caused by a misconfigured website. However, there are some steps you can take to ensure the issue isn’t on your side. You can find more details about redirecting URLs by reading the Google Search Central overview. In this article, we’ll go over how you can fix the Redirect to non-www and non-https in htaccess error on your web browser. Problem :
Solution :
We hope that this article has helped you resolve the htaccess, redirects, https error in your web browsers. Enjoy browsing the internet uninterrupted!
I need to redirect my WordPress blog from https://www.example.com/blog to http://example.com/blog using the .htaccess file. This is what I have so far:
<IfModule mod_rewrite.c>
Options +FollowSymlinks -MultiViews
RewriteEngine On
RewriteBase /
RewriteEngine On
RewriteCond %HTTPS on
RewriteCond %HTTP_HOST ^www.(.*)$ [NC]
RewriteRule (.*) http://%HTTP_HOST%REQUEST_URI [R=301,L]
</IfModule>
However, this only redirects from https to http but still keeps the www. How can I get rid of the www and remove the https at the same time? Any help would be appreciated.
Try with these lines only to switch from https to http:
RewriteEngine On
RewriteCond %HTTPS on
RewriteRule (.*) http://%HTTP_HOST%REQUEST_URI [R=301,L]
if not working, look for 301 redirect https to http. This topic is well covered aleady.
To remove the www:
<IfModule mod_rewrite.c>
RewriteEngine on
# Set "protossl" to "s" if we were accessed via https://. This is used later
# if you enable "www." stripping or enforcement, in order to ensure that
# you don't bounce between http and https.
RewriteRule ^ - [E=protossl]
RewriteCond %HTTPS on
RewriteRule ^ - [E=protossl:s]
# To redirect all users to access the site WITHOUT the 'www.' prefix,
# (http://www.example.com/... will be redirected to http://example.com/...)
# uncomment the following:
RewriteCond %HTTP_HOST ^www.(.+)$ [NC]
RewriteRule ^ http%ENV:protossl://%1%REQUEST_URI [L,R=301]
These lines are coming from the Drupal .htaccess but it should work whatever.
In the RewriteRule you have, you are using %HTTP_HOST whereas; it should be the matched part from the previous RewriteCond statement:
RewriteCond %HTTPS on
RewriteCond %HTTP_HOST ^www.(.*)$ [NC]
RewriteRule (.*) http://%1%REQUEST_URI [R=301,L]
Comments
Post a Comment