Take the 2-minute tour ×
ExpressionEngine® Answers is a question and answer site for administrators, end users, developers and designers for ExpressionEngine® CMS. It's 100% free, no registration required.

I would like to remove duplicate URLs by removing the trailing slash from URLs. If someone enters a URL like http://example.com/something/ it should 301 redirect to http://example.com/something.

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/example.com/
# RewriteCond $1 !\.(gif|jpe?g|png)$ [NC]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ /~macuser/example.com/index.php?/$1 [L]
</IfModule>

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

share|improve this question
add comment

1 Answer 1

up vote 2 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="www.google.nl/"} or {exp:remove_trailing_slash}www.google.nl/{/remove_trailing_slash}

http://reinos.nl/add-ons/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
add comment

Your Answer

 
discard

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.