2

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.

1

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.

  • It still has the www in the URL. – Daniel Harris Nov 12 '15 at 16:41
  • I have updated the answer – xaa Nov 12 '15 at 16:52
1

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]

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.