rewrite redirect not working under 3.3.24

Discussion in 'Bug Reports' started by aww, Jan 31, 2009.

  1. aww

    aww New Member

    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?
  2. mistwang

    mistwang LiteSpeed Staff

    Please enable rewrite log with "RewriteLogLevel 9" for that vhost.
    It should not be affected.
  3. aww

    aww New Member

    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: Feb 1, 2009
  4. aww

    aww New Member

    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.
  5. mistwang

    mistwang LiteSpeed Staff

  6. aww

    aww New Member

    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
  7. aww

    aww New Member

    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.
  8. aww

    aww New Member

    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: Feb 1, 2009
  9. mistwang

    mistwang LiteSpeed Staff

    we will investigate.
  10. aww

    aww New Member

    Was anything discovered about this?
  11. mistwang

    mistwang LiteSpeed Staff

    You can try the 4.0rc1 release.
  12. mistwang

    mistwang LiteSpeed Staff

    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.
  13. aww

    aww New Member

    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: Feb 24, 2009
  14. mistwang

    mistwang LiteSpeed Staff

    "RewriteOptions inherit" will be added.
  15. aww

    aww New Member

    Ah, thank you very much.

Share This Page