View Full Version : rewrite redirect not working under 3.3.24
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?
mistwang
01-31-2009, 04:32 PM
Please enable rewrite log with "RewriteLogLevel 9" for that vhost.
It should not be affected.
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
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.
mistwang
01-31-2009, 07:45 PM
I tried a similar rule with http://www.store.litespeedtech.com, it works.
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
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.
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 www.store.litespeedtech.com/testing123/
and it will NOT redirect to the URL without the www.
mistwang
02-01-2009, 07:43 PM
we will investigate.
Was anything discovered about this?
mistwang
02-13-2009, 09:48 PM
You can try the 4.0rc1 release.
mistwang
02-24-2009, 01:12 PM
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.
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.
mistwang
02-24-2009, 02:29 PM
"RewriteOptions inherit" will be added.