tags:

views:

510

answers:

3

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.

+1  A: 

Untested, but can't you just do this?

RewriteRule ^(.*[^/])$ $1/
RewriteRule ^(page-one|page-two|page-three)?$ /index.php?page=$1 [L]
Konrad Rudolph
+1  A: 

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!

hop
A: 

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]
Andrew G. Johnson