Re: Rewrite Rules, SSL, and .htaccess

From: davec (davec_at_webpipe.net)
Date: 04/02/04

  • Next message: Gord Philpott: "Re: iptables firewall script for debian-woody, 2.4.24"
    To: jm@gblx.net
    Date: Fri, 02 Apr 2004 00:47:46 -0700
    
    

    > davec wrote the following on 03/28/04 18:31:
    >>> RewriteEngine on
    >>> RewriteBase /usr/local/website
    >>> RewriteCond %{SERVER_PORT} !^443$
    >>> RewriteRule ^(.*)?$ https://%{SERVER_NAME}/$1 [L,R]
    >>
    >>
    >> This seems to work for all cases except when I enter www.mydomain.com/dir
    >> without the final trailing slash, and then I get a 404 error. I did a
    >> little more research and found a rule that seems to work (inside the
    >> Directory tag) only for that special case:
    >> RewriteRule ^$ https://%{SERVER_NAME}/dir/ [L,R]
    >> The rule only works when it is by itself. I tried to combine them like
    >> this:
    >> RewriteRule ^$ https://%{SERVER_NAME}/dir/ [L,R]
    >> RewriteRule ^(.*)?$ https://%{SERVER_NAME}/$1 [L,R]
    >> Then I get the same 404 error as before when I leave out the trailing
    >> slash. How can I get both of these rules to work together?
    >> Thanks,
    >> Dave
    >
    > ahh.. the "trailing slash" problem with Apache..
    >
    > <URL:
    > http://www.onlamp.com/pub/a/apache/2004/02/19/apache_ckbk.html?page=2>
    >
    > a quote from the above article:
    > "The "trailing slash" problem can be caused by one of two configuration
    > problems: an incorrect or missing value of ServerName, or an Alias with a
    > trailing slash that doesn't work without it."

    The link above did not seem to solve the problem. After searching a little
    more I found the following RewriteRule combination that seems to fix the
    problem:

    RewriteRule ^/usr/local/website/dir$ ""
    RewriteRule ^(.*) https://%{SERVER_NAME}/dir/$1 [L,R]

    The apache log showed the following string when I accessed the link without
    the trailing slash, "dir//usr/local/website/dir" so I had to strip out the
    "/usr/local/website/dir" to get back to the correct directory location
    relative to the web root.

    Thanks for all the help and responses.

    Dave


  • Next message: Gord Philpott: "Re: iptables firewall script for debian-woody, 2.4.24"

    Relevant Pages

    • Is there a workaraound for Trailing slash error?
      ... Our iis server was recently upgradedor patched with some sort of ... security "fix" - there is a problem though which is now occuring - URLs ... without a trailing slash - I am told this is a bug and that MS will ...
      (microsoft.public.inetserver.iis.security)
    • Re: Is there a workaraound for Trailing slash error?
      ... Too bad we don't know the fix that was installed. ... If the fix involved URLscan, ... > without a trailing slash - I am told this is a bug and that MS will ... Is there any sort of ...
      (microsoft.public.inetserver.iis.security)
    • [PATCH 0/2] get_maintainer improvements
      ... Arnd Bergmann pointed out that the directory pattern trailing slash ... He also sent a patch to ... fix it which I've modified a bit. ...
      (Linux-Kernel)