Im trying to implement 2 rules
1) Forced www.
I have got it working by doing
RewriteCond %{HTTP_HOST} ^domain.com
RewriteRule (.*) http://www.domain.com/$1 [R=301,L]
2) Add trailing forward slash on all urls
I got this far by doing this
RewriteCond %{HTTP_HOST} ^domain.com
RewriteRule (.*) http://www.domain.com/$1/ [R=301,L]
and then I ran into a problem,
type url
1) www.domain.com --rewrites to--> http://www.domain.com/ ---Desired Result
2) domain.com --rewrites to--> http://www.domain.com// ---Undesired Result
3) domain.com/location1 --rewrites to--> http://www.domain.com/location1/ ---Desired Result
4) www.domain.com/location1 --rewrites to--> http://www.domain.com/location1 ---Undesired Result
How can I write it so that i get these 2 rules working?
this rule will redirect all visits without the www:
See that I removed the flag to make it the last rule.
and the second one to put the trailing slash:
It won’t redirect when the URL already ends in a slash. You’ll get 2 redirects when someone visits a page without the www and without the slash. If you just want to do this due to search engines, it is fine. If your own site often point to a URL like this, you’ll need another regexp.
If SEO is your motive, also take a look to canonical URLs