Reputation: 11
i would like to redirect my site form www to non-www url with ssl certificate. i have write the code
RewriteCond %{HTTP_HOST} ^www\.(.*)
RewriteRule ^.*$ https://\%1/$1 [R=301,L]
that works but if url have any get request it'll get redirect to the home page.
Upvotes: 1
Views: 77
Reputation: 3083
Try this:
Redirect www urls to non-www
RewriteEngine on
RewriteCond %{HTTP_HOST} ^www\.yoursite\.com [NC]
RewriteRule ^(.*) https://yoursite.com/$1 [R=301,L]
OR Alternative code that you can use:
RewriteEngine on
RewriteCond %{HTTP_HOST} !^example\.com
RewriteRule ^(.*) https://example.com/$1 [R=301,L]
Upvotes: 0
Reputation: 42895
Your $1
does not resolve to any value until you caputure some value in your RewiteRule
:
RewriteEngine on
RewriteCond %{HTTP_HOST} ^www\.(.+)$
RewriteRule ^(.*)$ https://%1/$1 [R=301,L]
PS: I made some additional minor modifications.
Upvotes: 1