Author image
Senior Developer

Removing that pesky trailing slash

So, it's perfectly valid to visit a site using a URL like:

But some pesky SEO types will complain that the site is accessible at two URLs and that you need do a 301 redirect to the canonical URL ( What you want to do is remove the trailing slashes using mod rewrite.

If you really need to do this, then you can just pop the following in the .htaccess file that Drupal provides:

  # Remove multiple slashes after domain
  RewriteCond %{HTTP_HOST} !=""
  RewriteCond %{THE_REQUEST} ^[A-Z]+\s//+(.*)\sHTTP/[0-9.]+$
  RewriteRule .* http://%{HTTP_HOST}/%1 [R=301,L]

just before the # Rewrite URLs of the form 'x' to the form 'index.php?q=x'. line.

This should redirect any visitors with extra slashes after the domain to the canonical URL without slashes.

Now you can get back to real development, go!


Or simply enable the feature within GlobalRedirect ;-)

Lame! Really?

Does the Global Redirect removal of the trailing slash work with the root level of the domain, or just on sub pages?

Surely there is only an SEO issue if you have links pointing to your site with multiple trailing slashes?

This is unlikely to happen often!


Comments on this article are now closed, if you want to give us feeback you can use our contact form instead.