0

This question is related to How to configure Django to redirect multiple slashes (/) to single slash

I use Apache/mod_wsgi and I want 301 redirect instead of Apache just removing the slashes.

Paul R
  • 2,631
  • 3
  • 38
  • 72

2 Answers2

1

This situation is simple to resolve using a tasty slice of .htaccess.

All you need to do is copy the following code and place it anywhere in your site's root .htaccess file:

   # Remove double or triple forward slashes
   <IfModule mod_alias.c>
    RedirectMatch 301 ^///?(.*)$ http://example.com/$1
   </IfModule>

For Example:

 *  http://example.com// redirects to http://example.com/
 *  http://example.com//blog-post/ redirects to http://example.com/blog-post/
 *  http://example.com//path/directory/ redirects to http://example.com/path/directory/

I got the answer from this blog

Ruben Helsloot
  • 12,582
  • 6
  • 26
  • 49
Gilbish Kosma
  • 739
  • 5
  • 13
0

If you are using Apache can't you simply do this with mod_alias

i.e. (where foo.bar is your domain)

# Remove multiple forward slashes
<IfModule mod_alias.c>
    RedirectMatch 301 ^//+(.*)$ https://foo.bar/$1
</IfModule>
Fraser
  • 15,275
  • 8
  • 53
  • 104