301 "Moved permanently" glitch

Discussion in 'Bug Reports' started by embed, Feb 29, 2008.

  1. embed

    embed Member

    Hello, I noticed this issue using a rewrite rule like this:

    RewriteRule ^/old-dir/$ /new-dir/ [R=301,L]

    When I request http://www.mydomain.com/old-dir/ I correctly get a http response with the location header correctly set, i.e.:
    Location: http://www.mydomain.com/new-dir/
    So far, so good.

    Still, if the user hasn't automatic redirection active on her browser she will get the hardcoded 301 page, which has a broken link.

    The link on the page will be:
    <A HREF="http://www.mydomain.com/old-dir/%s">here</A>

    The link has two problems:
    1) It points to the old URI, which has been moved.

    2) There is a "%s" appended at the end which shouldn't be there.

    Maybe also the pages for the other redirection codes are broken. I didn't check.

    This may have slipped through easily since it's extremely rare that a visitor hasn't automatic redirection enabled.
    Still I think that this behaviour should be fixed.
    Thank you!
  2. mistwang

    mistwang LiteSpeed Staff

    It is a known issue, which have been intentionally left that way. I guess we have to fix it sooner or later as people keep reporting it. ;)

  3. embed

    embed Member

    Hello, I'm again experiencing something strange related to 301 redirections.
    At this point I can't say if this is a bug or the desired behaviour, still I could use a piece of advice.

    I'm trying to redirect any request to mydomain.com to www.mydomain.com.
    These are the rules I'm using:

    RewriteCond %{HTTP_HOST} ^mydomain\.com [NC]
    RewriteRule ^/(.*)$ http://www.mydomain.com/$1 [R=301,L]

    This works without any issue, if I request something like mydomain.com/foo I get a 301 redirect to www.mydomain.com/foo. If I disable automatic redirection in the browser I get lsws hardcoded 301 page as expected.

    Then I tried using a custom 301 page and things stopped working.
    If I define a custom 301 page through the webinterface, say /my301.html, when I ask for mydomain.com/bar I get a redirection to www.mydomain.com/my301.html and the default lsws 301 page shows up.

    I am successfully using a custom 301 page for other redirects that don't use backreferences.
    I tried $0 too but it gives the same result as $1, as I would have expected. Also $2 is empty, as it should be.

    Maybe I'm missing something obvious here. Still, I don't think that the backreference should contain the filename of my custom 301 page.
    Any suggestion would be most welcome, thanks for your attention.
  4. mistwang

    mistwang LiteSpeed Staff

    Looks like a real bug, will look into it.
  5. embed

    embed Member

    When I saw the changelog for v3.3.8 I thought that maybe the backreference issue could have been solved.
    Since it isn't the case I'd like to know if there is any chance for this problem to be fixed before v4.0.
  6. mistwang

    mistwang LiteSpeed Staff

    Checked the issue, that because the rewrite rule has been executed again when process the custom error page, you need to change the rewrite rule to

    RewriteCond %{REQUEST_URI} !^/my301.html
    RewriteCond %{HTTP_HOST} ^mydomain\.com [NC]
    RewriteRule ^/(.*)$ http://www.mydomain.com/$1 [R=301,L]
  7. embed

    embed Member

    Thank you for the suggestion, it worked perfectly.

    Yet, I encountered another strangeness that should be of interest in this context.

    If I have the request filter enabled and a rule like this one:
    SecFilterSelective REQUEST_URI "badword"

    requesting something like:

    gives me the hardcoded 301 page and not my custom error page. If I remove the rule I get the custom 301 page.

    The location header in the http response correctly reports http://www.mydomain.com/foo-badword-bar
    and when the user follows the redirect the request filter blocks the new request as it should.

    Is there any way to get the custom 301 page instead of the hardcoded one? I don't know if this happens for the other redirects also.
  8. mistwang

    mistwang LiteSpeed Staff

    That because the security engine check the original request URI against the security rule when processing the custom error page, and block it. Do not have good work around for this yet.
  9. mistwang

    mistwang LiteSpeed Staff

    This should work better with 3.3.9 release now.
  10. embed

    embed Member

    Yes, in v3.3.9 the issue related to the request filter is gone. Thank you.

Share This Page