<p>Craft has a config setting for this (for dynamic urls)</p>

<p>You can set it in your config file like so:</p>

<pre><code>'addTrailingSlashesToUrls' =&gt; true
</code></pre>

<p>If someone links to the url via a non-trailing-slash pattern, it should redirect.</p>

<p>If you use an apache rewrite, you can exclude the craft admin by checking the uri pattern</p>

<pre><code>RewriteCond %{REQUEST_URI} !(admin)$
RewriteRule ^(.*)([^/])$ http://%{HTTP_HOST}/$1$2/ [L,R=301]
</code></pre>

CC BY-SA 3.0
2016-02-24T19:30:18.427Z
2016-02-24T19:30:18.427Z
Jbird
<p>I found by just adding the code from the <a href="http://www.paulund.co.uk/using-htaccess-to-force-trailing-slash" rel="nofollow">following site</a> it will add slashes via a 301 redirect:</p>

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

<p>Now my .htaccess file looks like the following:</p>

<pre><code>&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;
</code></pre>

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

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

<p>Here is a third option which seems to work as well:</p>

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

<p><em>I'll update once I've researched and settled upon the best option.</em></p>

CC BY-SA 3.0
2015-04-29T00:54:47.323Z
Note: these need to go before the default Craft rewrite.
Natetronn
CC BY-SA 3.0
2015-05-22T22:58:59.650Z
I don't think it should be adding this onto the dashboard URLs. We'll have to come up with a solutions which takes that into consideration.
Natetronn
CC BY-SA 3.0
2015-04-28T23:05:29.580Z
2015-04-29T00:52:53.693Z
2015-04-29T00:52:53.693Z
Natetronn
<p>This is an .htaccess question which I found the answer to but, I need to integrate it with the .htaccess that comes with Craft.</p>

<p>I need to add trailing slashes to the end of all URLs.</p>

<p>I know there is a General Config Setting for <a href="http://buildwithcraft.com/docs/config-settings#addTrailingSlashesToUrls" rel="nofollow">adding trailing slashes to URLs</a> 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.</p>

<p>For example:</p>

<p><code>http://mydomain.dev/news/news-entry</code> </p>

<p>would 301 redirect to </p>

<p><code>http://mydomain.dev/news/news-entry/</code></p>

<p>This is what comes with Craft by default:</p>

<pre><code>&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;
</code></pre>

<url><redirect><redirection>
Force trailing slash on URLs
# Force trailing slash on URLs

(Asked by: username_0 on 2015-04-28)

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:

    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]

**Tags:** url, redirect, redirection


---

## 2 answers

### Answer by username_1 on 2016-02-24. Score: 5

Craft has a config setting for this (for dynamic urls)
You can set it in your config file like so:
'addTrailingSlashesToUrls' => true

If someone links to the url via a non-trailing-slash pattern, it should redirect.
If you use an apache rewrite, you can exclude the craft admin by checking the uri pattern
RewriteCond %{REQUEST_URI} !(admin)$
RewriteRule ^(.*)([^/])$ http://%{HTTP_HOST}/$1$2/ [L,R=301]


---

### Answer by username_0 on 2015-04-28. Score: 4

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:

    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]



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.

> **Comments:**
> **username_0**: Note: these need to go before the default Craft rewrite.  
> **username_0**: I don't think it should be adding this onto the dashboard URLs. We'll have to come up with a solutions which takes that into consideration.  

---

