0

we have urls as;

 - mydomain.com/my-keyword/
 - mydomain.com/my-other-keyword/
 - mydomain.com/my-another-keyword/

and also

 - mydomain.com/my-keyword/a-page.html
 - mydomain.com/my-keyword/another-page.html
 - mydomain.com/my-other-keyword/some-page.html
 - mydomain.com/my-other-keyword/any-page.html
 - mydomain.com/my-another-keyword/another-page.html
 - mydomain.com/my-another-keyword/some-page.html

We want to convert (301) all urls created without / for example; mydomain.com/my-another-keyword -> to -> mydomain.com/my-another-keyword/ without harming the rest of the url structure.

Any ideas?

2 Answers 2

0
RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_URI} !(.*)/$
RewriteRule ^(.*)$ http://mydomain.com/$1/ [L,R=301] 

if the file exists: dont add slash, if it's not a file: add slash

1
  • this would NOT work, because we dont have a files with those names. Basically our original rewrite can rewrite anything regardless of what address is called as long as keyword exists. It will pull out the details and print them on page. mydomain.com/colorado-hotels/ or mydomain.com/colorado_hotel/ They both bring out the same data. So obviously mydomain.com/colorado_hotel will also work. Thanks but, this is why yours is no good. Any ideas ?
    – hasbehas
    Jul 8, 2011 at 11:13
0

This should work for you as long as a "directory" in the path does not contain a .

RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_URI} !\..+$
RewriteCond %{REQUEST_URI} !/$
RewriteRule (.*) http://domain.com/$1/ [R=301,L]

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .