rewrite redirect not working under 3.3.24

aww

Well-Known Member
#1
This used to work and I just noticed under 3.3.24 it's no longer working:

RewriteCond %{HTTP_HOST} !^websitename\.com
RewriteRule ^(.*)$ http://websitename.com/$1 [L,R]

(it's to enforce no-www on URLs)

Works fine under apache, used to work under Litespeed.
Did something break?
 

aww

Well-Known Member
#3
Okay I did that (by the way, it would be nice if that worked from .htaccess as well, though I guess it would be a security issue as it could overflow the logs)

but there are no errors, only this info line, when I access it with www.websitename.com (it should be redirected to websitename.com but it's not)

2009-01-31 20:49:48.900 INFO [12.34.56.78:2594-4#APVH_websitename.com] [REWRITE] Cond: Match 'websitename.com' with pattern '^websitename\.com', result: 1
 
Last edited:

aww

Well-Known Member
#4
Hmm, wait now I see

12.34.56.78:2822-1#APVH_websitename.com] [REWRITE] Cond: Match 'www.websitename.com' with pattern '^websitename\.com', result: -1

So that's false, then there's a ! in front of it to negate it and that should be true.

But it doesn't seem to ever execute the redirect.
 

aww

Well-Known Member
#6
I tried something in a different directory that had no other rules and yes it works.

But that means a lower level rule is interfering with a higher level rule which should not happen.

the .htaccess in the webroot should execute first, before any in a sub-directory, no?

keep in mind it works on apache - I will have to look at this line by line now to debug
 

aww

Well-Known Member
#7
Yup with JUST that rule in the webroot, some lower level rules which have nothing to do with external redirects, only internal rewrites, screw it up - it never redirects.

I'll try to come up with a minimal example.
 

aww

Well-Known Member
#8
I have found the bug, and it is real.

All it takes is for a sub-directory to have the directive:

RewriteEngine On

in it's own sub .htaccess, and the parent redirect will never happen.
No other rule is present in the subdirectory.
If I remove that RewriteEngine On - the redirect will work properly, even with other rules.

Apparently "RewriteEngine On" causes the rewrite engine in litespeed to reset.
This is not the behaviour in apache, which will ignore it if it's already on.

Try making a sub-directory called /testing123/
and make a .htaccess in it
and put in the .htaccess
RewriteEngine On

then go to
Code:
www.store.litespeedtech.com/testing123/
and it will NOT redirect to the URL without the www.
 
Last edited:

mistwang

LiteSpeed Staff
#12
I have found the bug, and it is real.

All it takes is for a sub-directory to have the directive:

RewriteEngine On

in it's own sub .htaccess, and the parent redirect will never happen.
No other rule is present in the subdirectory.
If I remove that RewriteEngine On - the redirect will work properly, even with other rules.

Apparently "RewriteEngine On" causes the rewrite engine in litespeed to reset.
This is not the behaviour in apache, which will ignore it if it's already on.
After study the behavior of Apache rewrite implementation, it is the correct behavior.
If you put only "RewriteEngine On" in a .htaccess without any rewrite rules or "RewriteOptions inherit", Apache will not look for other rewrite rules in parent directories.
Tested it on Apache 2.2 .
So, we will change our rewrite engine implementation to match Apache's.
 

aww

Well-Known Member
#13
Oh!
Is that the problem?
Does Litespeed not currently support "RewriteOptions inherit" ?

For some reason I thought it was working on my apache test server without "RewriteOptions inherit" but just double checked now and you are correct, without "RewriteOptions inherit" the www. rewrite rule doesn't recurse.

But it does work with that on, on Apache. Not on litespeed however.
 
Last edited:
Top