skip to Main Content

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.

2

Answers


  1. 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>
    
    Login or Signup to reply.
  2. 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

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search