2

I am really stuck at conversion of this beautiful htaccess script (rule) which force non-www to www url considering the http or https its perfectly working but I cant make it work opposite way from www to non-www can you please help me?

RewriteCond %{HTTP_HOST} !^www\.
RewriteCond %{HTTPS}s ^on(s)|
RewriteRule ^ http%1://www.%{HTTP_HOST}%{REQUEST_URI} [R=301,L]

Thank you I am really stuck at those htaccess symbols!

Marek Čech
  • 105
  • 11
  • possible duplicate of [htaccess redirect for non-www both http and https](http://stackoverflow.com/questions/2015159/htaccess-redirect-for-non-www-both-http-and-https) – spinsch Jul 25 '13 at 06:06

1 Answers1

4

For making www to non-www above code will not work because of the way variable capturing works in RewriteCond. You need to break them into 2 rules like this:

RewriteCond %{HTTPS} off
RewriteCond %{HTTP_HOST} ^www\.(.+)$ [NC]
RewriteRule ^ http://%1%{REQUEST_URI} [R=301,L]

RewriteCond %{HTTPS} on
RewriteCond %{HTTP_HOST} ^www\.(.+)$ [NC]
RewriteRule ^ https://%1%{REQUEST_URI} [R=301,L]
anubhava
  • 761,203
  • 64
  • 569
  • 643