Add trailing slash

Hi,

Is it possible to write a rule that will add a slash to a URL that someone enters?

My website is setup like this:

www.domain.com/folder/

If someone enters www.domain.com/folder the page will not load.
www.domain.com/folder/ the page loads correctly.

There is an index file in each folder.

I have tried this but it does not work.


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

JB,

Actually, your server should be setup to determine whether the request is a directory and then select the DirectoryIndex from that directory. In other words, complain to your host (first).

Then, to show your host that you’re smarter than they are, REMOVE the useless RewriteBase directive, test for the request being a directory THEN redirect to add the trailing /, i.e.,

RewriteEngine on
RewriteCond %{REQUEST_FILENAME} -d
RewriteRule .? http://www.example.com%{REQUEST_URI}/ [R=301,L]

When you create a specification, you can see the clearest path to actually writing the code. You wanted to add the trailing / to a directory request so that should have been your test and everything else just falls into place.

Regards,

DK