ExpressionEngine® Answers is a question and answer site for administrators, end users, developers and designers for ExpressionEngine® CMS. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I would like to remove duplicate URLs by removing the trailing slash from URLs. If someone enters a URL like it should 301 redirect to

Obviously the query string must be preserved when present.

Here is my .htaccess file at the moment (for localhost):

Options +FollowSymlinks

<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /~macuser/
# RewriteCond $1 !\.(gif|jpe?g|png)$ [NC]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ /~macuser/$1 [L]

Also, please feel free to comment if the above can be improved in any way.

share|improve this question
up vote 3 down vote accepted

For your .htacces you can use

# remove trailing slash
RewriteRule ^(.*)\/(\?.*)?$ $1$2 [R=301,L]

To improve the urls on your page you can use my little plugin called 'remove_trailing_slash'. It is not yet aproved by devot-ee, but i can send you the plugin right away.

The usage is simple:

{exp:remove_trailing_slash url=""} or {exp:remove_trailing_slash}{/remove_trailing_slash}

Please pm me your email so i can send it to you.

share|improve this answer
Awesome thanks that worked a charm!! I do not think that I need to process the URLs in my output HTML because those do not include trailing slashes (or at least none that I am aware of). – Lea Hayes Dec 29 '12 at 15:20

I used the following in my htaccess to redirect the urls with a trailing slash:

RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{HTTP_HOST} !^\.localhost$ [NC]
RewriteRule ^(.+[^/])/$ http://%{HTTP_HOST}/$1 [R=301,L]
share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.