We help IT Professionals succeed at work.

htaccess rewrite all urls ending with /

zattz asked
Hi all,

Can somebody show me how to htaccess rewrite all urls that end in a slash so that they 301 redirect to the same page without the slash?

EG: www.domain.com/this/ must 301 to www.domain.com/this

thanks :)
Watch Question

Top Expert 2005
First of all You don't want do that in fact. Apache can't handle www.domain.com/this request, it rewrites it internally (with mod_dir usually) to www.domain.com/this/ anyway.

So why would You want to do it? People usually want the backward.

Anyway - into .htaccess
Option +FollowSymLinks
RewriteEngine On
#if it points to existing directory
RewrteCond %{REQUEST_URI} -d
RewriteRule ^(.*)/$ $1 [L,R=301]

Explore More ContentExplore courses, solutions, and other research materials related to this topic.