Mobile app version of vmapp.org
Login or Join
Cofer257

: 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:

@Cofer257

Posted in: #Htaccess #Https #ModRewrite #NoWww #Redirects

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.

10.02% popularity Vote Up Vote Down


Login to follow query

More posts by @Cofer257

2 Comments

Sorted by latest first Latest Oldest Best

 

@Goswami781

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]

10% popularity Vote Up Vote Down


 

@Heady270

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.

10% popularity Vote Up Vote Down


Back to top | Use Dark Theme