#1
  1. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jan 2004
    Posts
    16
    Rep Power
    0

    Unhappy Rewrite rule not ignoring not-found parameter


    Can you help me find out what's wrong with this?

    I'm not an Apache programmer, one of the few things I thought I do know is that -f means "is not a file", which triggers when "not found", but now i doubt it.

    These are my rules, and the problem is that the verification file from google e.g. /8377rsomecode.html is not found (it's a real file, not a wordpress page)

    It should be NOT catched by line marked with ***********

    Code:
    <IfModule mod_rewrite.c>
    RewriteEngine On
    RewriteBase /
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteRule ^blog/(.*)\.html http://%{SERVER_NAME}/$1 [R=301,L]
    #
    RewriteCond %{HTTP_HOST} =!blog/page/.*
    RewriteCond %{HTTP_HOST} =!blog/tag/.*
    RewriteCond %{HTTP_HOST} =!blog/category/.*
    RewriteRule ^blog/(.*) http://%{SERVER_NAME}/$1 [R=301,L]
    # remaining.html files
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteRule ^(.*)\.html$ /$1 [R=301,L]************
    #
    # BEGIN WordPress
    <IfModule mod_rewrite.c>
    RewriteEngine On
    RewriteBase /
    RewriteRule ^index\.php$ - [L]
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteRule . /index.php [L]
    </IfModule>
    
    # END WordPress
  2. #2
  3. Transforming Moderator
    Devshed Supreme Being (6500+ posts)

    Join Date
    Mar 2007
    Location
    Washington, USA
    Posts
    14,126
    Rep Power
    9398
    Other than the bits using HTTP_HOST I don't see anything wrong. But they wouldn't have anything to do with your problem so that's not it.

    Just to be clear, if you tried going to /8377rsomecode.html by yourself in a browser, you get redirected to /8377rsomecode (no extension) and then, presumably, WordPress's 404 page?
  4. #3
  5. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jan 2004
    Posts
    16
    Rep Power
    0

    Update


    when I say /something.html I mean after my domain.com of course.

    Can you tell me why that will be redirected to the same thing without .html?

    I believe the first redirect rules dealing with .html only does it to urls containing /blog/ and my example doesn't have it.

    UPDATE: The page is not retrieved because a redirection loop, rather than not found at all.

    I tried removing

    Code:
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteRule ^(.*)\.html$ /$1 [R=301,L]************
    and it works. So the problem must be the first rule dealing with .html is either not stopping there as the parameter [L] says, or working on ALL pages, not only the ones with /blog/ in it.
  6. #4
  7. Transforming Moderator
    Devshed Supreme Being (6500+ posts)

    Join Date
    Mar 2007
    Location
    Washington, USA
    Posts
    14,126
    Rep Power
    9398
    The Rules:
    1. Redirects /blog/foo.html to /foo but only if it doesn't exist.
    2. Will never fire.
    3. Redirects /foo/bar/baz.html to /foo/bar/baz but only if it isn't a file.
    4. Allows index.php.
    5. Silently rewrites everything non-existent to index.php.

    If your verification file really does exist then none of the Rules should fire.
  8. #5
  9. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jan 2004
    Posts
    16
    Rep Power
    0

    Fixed it, but seems I still don't understand regexes in rewrites


    Originally Posted by requinix
    2. Will never fire.
    Why? The 6th line matches requests ending with .html but ALSO blog/
    Line #14 should catch the rest of .html files (not cached before because they don't contain /blog/ )
    I'm wrong right? I can't see why, sorry

    If your verification file really does exist then none of the Rules should fire.
    That's the idea.

    UPDATE: I made it work by adding the following condition to the first rule:

    Code:
    RewriteCond %{HTTP_HOST} =/blog/.*
    So why was ^blog/(.*)\.html not ignoring requests lacking blog/ ?

    Was it the missing first forward slash?
  10. #6
  11. Transforming Moderator
    Devshed Supreme Being (6500+ posts)

    Join Date
    Mar 2007
    Location
    Washington, USA
    Posts
    14,126
    Rep Power
    9398
    HTTP_HOST is the hostname of the site. Like here it's "forums.devshed.com" and on your site it's "domain.com". So

    - #2 will never fire because the Conds never match. Putting aside the fact that the three of them are mutually exclusive (because Conds are all ANDed by default), they all require that the domain name is exactly (for example) "!blog/page/.*".

    - What you've done now is add a condition that will never match. The domain name will never be exactly equal to "/blog/.*" thus that Rule will never fire.

IMN logo majestic logo threadwatch logo seochat tools logo