: Redirect to non-www and non-https in htaccess 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:
I need to redirect my WordPress blog from www.example.com/blog to 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_HOST}%{REQUEST_URI} [R=301,L]
</IfModule>
However, this only redirects from https to http but still keeps the How can I get rid of the www and remove the https at the same time? Any help would be appreciated.
More posts by @Cofer257
2 Comments
Sorted by latest first Latest Oldest Best
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 (.*) %1%{REQUEST_URI} [R=301,L]
Try with these lines only to switch from https to http:
RewriteEngine On
RewriteCond %{HTTPS} on
RewriteRule (.*) %{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 . 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 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.
Terms of Use Create Support ticket Your support tickets Stock Market News! © vmapp.org2024 All Rights reserved.