Web Design. Web Development. Web Hosting.
0 items

htaccess Remove Multiple Slashes in URL

Need Some Help? We are here for you!

We have a very friendly service - Come and chat to us and let us know what you need, we work for an hourly fee and can also provide you a no obligation quote and begin work immediately in most cases. Click "Request Support" or use our Live Chat.

Request Support

Apache is a beast, a big untamed beast that sometimes releases a huge surprise that confuses, perplexes and even scares the living shit out of you, such as when you realise that Apache doesnt care about multiple slashes (empty directories?? WHAT ON EARTH?!?), which I have just coined #slashesgate.

So what is this seriously messed up and confusing issue in Apache you wonder? Maybe you noticed this yourself and found this article while trying to find a fix, lets start by explaining the issue…

Lets take an ordinary url such as: https://webdesires.co.uk/knowledge-base/htaccess-remove-multiple-slashes-in-url/

Here what #slashesgate can do:

https://webdesires.co.uk/////knowledge-base/htaccess-remove-multiple-slashes-in-url/

https://webdesires.co.uk/knowledge-base//////htaccess-remove-multiple-slashes-in-url/

https://webdesires.co.uk/knowledge-base/htaccess-remove-multiple-slashes-in-url//////

 

For some reason this behaviour is considered completely OK by Apache, what is worse is that it seems to just ignore the extra slashes and your website happily loads whatever normal page would exist without the multiple slashes. This presents a whole host of possible issues, most importantly concerning SEO attacks.

So can we stop #slashesgate? Yes we can! Just add these lines to your .htaccess file, and away we go.

<IfModule mod_rewrite.c>
 RewriteBase /

 # rule 1: removes multiple leading slashes directly after the domain name / TLD
 RewriteCond %{THE_REQUEST} \s/{2,}
 RewriteRule (.*) $1 [R=301,L]

 # rule 2: remove multiple slashes anywhere in the rest of the path
 RewriteCond %{REQUEST_URI} ^(.*)/{2,}(.*)$
 RewriteRule (.*) %1/%2 [R=301,L]
</IfModule>

 

With the code above you can stop the issue by Removing Double Or More Slashes From URL By .htaccess.

Hope this article helps.

4.7 3 votes
Article Rating
Need Some Help? We are here for you!

We have a very friendly service - Come and chat to us and let us know what you need, we work for an hourly fee and can also provide you a no obligation quote and begin work immediately in most cases. Click "Request Support" or use our Live Chat.

Request Support
Author: Dean WilliamsProfessional PHP Web Developer with expertise in OpenCart Web Development, WordPress Web Development, Bespoke Systems - also a seasoned Linux Server Administrator.


Subscribe
Notify of
1 Comment
Inline Feedbacks
View all comments
Dragos Arama
4 years ago

Best!



Share this page..

Let's Begin Your Journey...

Get in touch us now to begin your journey to having a beautifully crafted mobile responsive website. If you're still unsure what we could do for you then take a look at our Why Us page which includes reviews, or take a look at our Portfolio.

We can work on improving existing websites or craft a new stylish website making your business stand out.

You could always catch us by E-Mail, Telephone, Skype or Live Chat to us below.


    1
    0
    Would love your thoughts, please comment.x
    ()
    x