Reputation: 26993
This is a multi-site problem. I have a lot of sites with .htaccess files with multiple line similar to:
rewriterule ^(page-one|page-two|page-three)/?$ /index.php?page=$1 [L]
This means that both www.domain.com/page-one and www.domain.com/page-one/ will both load www.domain.com/index.php?page=page-one
However I'm always told that it is good SEO practice to make sure you use only one URL per page so what I'd like to do make www.domain.com/page-one to redirect to www.domain.com/page-one/ via the .htaccess file.
Please note the answer I'm NOT looking for is to remove the ?$ from the end of the line as that will just cause www.domain.com/page-one to become a 404 link.
Upvotes: 5
Views: 2897
Reputation: 26993
Here's a snippet to force everything to end with a slash
rewritecond %{REQUEST_FILENAME} !-f
rewritecond %{REQUEST_URI} !(.*)/$
rewriterule ^(.*)$ http://%{HTTP_HOST}/$1/ [L,R=301]
Upvotes: 4
Reputation:
Use an HTTP redirect to send users who use the "wrong" URL to the correct one. You could for example use:
RewriteRule ^(.+[^/])$ $1/ [R]
before your own RewriteRule.
Beware, though: this will also add slashes to URLs that end in a filename. If you have such URLs, you have to put exceptions for them before the redirect.
See also the FAQ entry on trailing slashes and the example page for mod_rewrite!
Upvotes: 2
Reputation: 545875
Untested, but can't you just do this?
RewriteRule ^(.*[^/])$ $1/
RewriteRule ^(page-one|page-two|page-three)?$ /index.php?page=$1 [L]
Upvotes: 1