Force trailing slash on URLs This is an .htaccess question which I found the answer to but, I need to integrate it with the .htaccess that comes with Craft.

I need to add trailing slashes to the end of all URLs.

I know there is a General Config Setting for adding trailing slashes to URLs to "dynamically-generated URLs" but, in the case there are any hard coded urls with out the trailing slashes or if someone links to the site without trailing slashes it would be nice to set it and forget it via the htaccess.

For example:

http://mydomain.dev/news/news-entry 

would 301 redirect to 

http://mydomain.dev/news/news-entry/

This is what comes with Craft by default:

&lt;IfModule mod_rewrite.c&gt;
    RewriteEngine On

    # Send would-be 404 requests to Craft
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteCond %{REQUEST_URI} !^/(favicon\.ico|apple-touch-icon.*\.png)$ [NC]
    RewriteRule (.+) index.php?p=$1 [QSA,L]
&lt;/IfModule&gt;
I found by just adding the code from the following site it will add slashes via a 301 redirect:

RewriteCond %{REQUEST_URI} /+[^\.]+$
RewriteRule ^(.+[^/])$ %{REQUEST_URI}/ [R=301,L]


Now my .htaccess file looks like the following:

&lt;IfModule mod_rewrite.c&gt;
    RewriteEngine On

    # 301 redirect with trailing slash
    RewriteCond %{REQUEST_URI} /+[^\.]+$
    RewriteRule ^(.+[^/])$ %{REQUEST_URI}/ [R=301,L]

    # Send would-be 404 requests to Craft
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteCond %{REQUEST_URI} !^/(favicon\.ico|apple-touch-icon.*\.png)$ [NC]
    RewriteRule (.+) index.php?p=$1 [QSA,L]

&lt;/IfModule&gt;


And here is another version/option which seems to work as well:

RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(.*[^/])$ /$1/ [L,R=301]


Here is a third option which seems to work as well:

# Always append a trailing slash
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_URI} !/$
RewriteRule . %{REQUEST_URI}/ [R=301,L]


I'll update once I've researched and settled upon the best option.