Reputation: 121
I am trying to always add www to my website and remove the slash at the end but only for the homepage.
I had this code:
RewriteCond %{HTTP_HOST} ^example.com [NC]
RewriteRule ^(.*)$ http://www.example.com$1 [L,R=301]
However, since it was always removing the slash it lead to a bunch of problems with our images etc (because it would be pointing on http://www.example.commedia instead of http://www.example.com/media).
Anyone could point me out how to do this ?
Upvotes: 0
Views: 32
Reputation: 6272
As stated in the apache2 docs you obtain the desired results with the following rules:
RewriteCond "%{HTTP_HOST}" "!^www\." [NC]
RewriteCond "%{HTTP_HOST}" "!^$"
RewriteRule "^/?(.*)" "http://www.%{HTTP_HOST}/$1" [L,R,NE]
Upvotes: 1