Apache Remove Double or Multiple Slashes (//) in URL?

Hi,

Apache seems to add an extra slash to URL. I googled the subject, but didn't find a solution that works in all cases:

example.com//

example.com//path1/path2//

How do I remove extra slashes or I should not bother about it at all?

2 Replies

Apache isn't doing that by default. It's something you've changed for example.

@waldo:

Apache isn't doing that by default. It's something you've changed for example.

An extra slash was added as a consequence of my RewriteRule:

 <virtualhost example.com:80="">ServerName example.com
    ServerAlias www.example.com
    DocumentRoot "/var/www/sites/example.com/current/public"
    ErrorLog "/var/log/apache2/example.com-error_log"
    CustomLog "/var/log/apache2/example.com-access_log" common
    <directory "="" var="" www="" sites="" example.com="" current="" public"="">Options All
        AllowOverride All
        Order allow,deny
        Allow from all</directory> 
    RewriteEngine On
    # Remove the www
    RewriteCond %{HTTP_HOST} ^www.example.com$ [NC]
    RewriteRule ^/(.*)$ http://example.com/$1 [L,R=301]</virtualhost> 

I added a slash to the ^/(.*)$ expression and it solved the problem.

Reply

Please enter an answer
Tips:

You can mention users to notify them: @username

You can use Markdown to format your question. For more examples see the Markdown Cheatsheet.

> I’m a blockquote.

I’m a blockquote.

[I'm a link] (https://www.google.com)

I'm a link

**I am bold** I am bold

*I am italicized* I am italicized

Community Code of Conduct