• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 270
  • Last Modified:

htaccess rewrite all urls ending with /

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 :)
1 Solution
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]

Featured Post

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now