htaccess force www to non-www with consideration of http or https
Asked Answered
O

1

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!

Ode answered 24/7, 2013 at 23:58 Comment(1)
possible duplicate of htaccess redirect for non-www both http and httpsSimson
S
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]
Setback answered 25/7, 2013 at 6:54 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.