mod_rewrite - remove double slash from url

#1
Hi

These rules work fine in apache, but they don't work in litespeed (using v4.0.20):

RewriteEngine On
RewriteCond %{REQUEST_URI} ^(.*)//(.*)$
RewriteRule . %1/%2 [R=301,L]

The purpose is to remove double (or more) slashes from URLs.

I've played around with it and it seems litespeed is not matching properly in the RewriteCond.

Can someone please help me on this one?
 

webizen

Well-Known Member
#2
LiteSpeed removes double (or more) slashes from URL internally before entering rewrite rules process. So there is no need for this. %

If you really want to use rewrite rules for this, use %{ORG_REQ_URI} instead of %{REQUEST_URI}.
 
#3
I had noticed that, sometimes, the url in the address bar got 'cleaned' from double slashes (with no rewrite rules at all). However, I haven't been able to reproduce this behaviour for a while -- it might have happened in another server.

Of course, that doesn't meen that LiteSpeed isn't cleaning them, it's just not issuing redirects, so the browser doesn't know of this.

To check this I wrote this php script (as index.php):
<?php echo 'REQUEST_URI = ' . $_SERVER['REQUEST_URI']; ?>

and when requesting these urls, i get:

http://my.domain/a//index.php --- REQUEST_URI = /a//index.php
http://my.domain/a/b/index.php --- REQUEST_URI = /a/b/index.php
http://my.domain/a/b --- REQUEST_URI = /a/b/
http://my.domain/a//b --- REQUEST_URI = /a//b/

It looks like LiteSpeed is passing the original REQUEST_URI to PHP, and not the filtered one.

I then went back to fiddle with .htaccess.

To be sure the RewriteRule was being satisfied, I tried a more obvious Cond:

RewriteCond %{ORG_REQ_URI} ^/a/$
RewriteRule .* http://example.com [R=301,L]

and it works! I get redirected when visiting http://my.domain/a/ (or /a because the server automatically always adds the last slash), as expected. But it doesn't redirect with my original condition.

My conclusion is that this condition isn't being matched:
RewriteCond %{ORG_REQ_URI} ^(.*)//(.*)/$

Any ideas of how can I sort this out?

I have a client getting 404s in urls with double slashes and wish to sort that out. He's using Magento.
 
Last edited:

webizen

Well-Known Member
#4
please do a force reinstall from lsws version manager in admin console. the latest 4.0.20 build supports %{REQUEST_URI} more like apache now.
 
Top