Mobile app version of vmapp.org
Login or Join
Barnes591

: Removing trailing slash ONLY for a specific directory I would like to 301 redirect my URL that has a trailing slash to a URL without a trailing slash. That part is simple (RewriteRule ^(.*)/(?.*)?$

@Barnes591

Posted in: #301Redirect #Apache #Redirects

I would like to 301 redirect my URL that has a trailing slash to a URL without a trailing slash. That part is simple (RewriteRule ^(.*)/(?.*)?$ [R=301,L])

However I only want to do it if that directory is /abc/

For example:

www.example.com/abc/cowboy/ should be 301ed to www.example.com/abc/cowboy http://www.example.com/xyz/cowboy/ should stay the same and NOT be 301ed

10.01% popularity Vote Up Vote Down


Login to follow query

More posts by @Barnes591

1 Comments

Sorted by latest first Latest Oldest Best

 

@Ogunnowo487

In your server config, you can modify your current example to include the /abc/ directory to restrict redirects to that one directory:

RewriteRule ^/abc/(.*)/(?.*)?$ /abc/ [R=301,L]


I've removed the backslash escape from the slash, in your example, as this would appear to be unnecessary.

Note that to make this work in .htaccess you would need to removed the slash prefix from the RewriteRule pattern.

10% popularity Vote Up Vote Down


Back to top | Use Dark Theme