The Shed is going Social! Join us on FaceBook and Twitter and chime in on the conversation.
|
 |
|
Dev Shed Forums
> System Administration
> Apache Development
|
Rewrite rule not ignoring not-found parameter
Discuss Rewrite rule not ignoring not-found parameter in the Apache Development forum on Dev Shed. Rewrite rule not ignoring not-found parameter Apache Development forum discussing HTTP Server general topics, configuration, and modules. Apache is an open source web server that runs on multiple platforms.
|
|
 |
|
|
|
|

Dev Shed Forums Sponsor:
|
|
|

April 11th, 2012, 03:20 AM
|
|
Registered User
|
|
Join Date: Jan 2004
Posts: 16
Time spent in forums: 3 h 7 m 50 sec
Reputation Power: 0
|
|
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
|

April 11th, 2012, 04:54 AM
|
 |
Still alive
|
|
Join Date: Mar 2007
Location: Washington, USA
|
|
|
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?
|

April 11th, 2012, 05:25 AM
|
|
Registered User
|
|
Join Date: Jan 2004
Posts: 16
Time spent in forums: 3 h 7 m 50 sec
Reputation 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.
|

April 11th, 2012, 05:56 PM
|
 |
Still alive
|
|
Join Date: Mar 2007
Location: Washington, USA
|
|
|
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.
|

April 11th, 2012, 06:46 PM
|
|
Registered User
|
|
Join Date: Jan 2004
Posts: 16
Time spent in forums: 3 h 7 m 50 sec
Reputation Power: 0
|
|
|
Fixed it, but seems I still don't understand regexes in rewrites
Quote: | 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
Quote: | 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?
|

April 11th, 2012, 07:28 PM
|
 |
Still alive
|
|
Join Date: Mar 2007
Location: Washington, USA
|
|
|
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.
|
Developer Shed Advertisers and Affiliates
| Thread Tools |
Search this Thread |
|
|
|
| Display Modes |
Rate This Thread |
Linear Mode
|
|
Posting Rules
|
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
HTML code is Off
|
|
|
|
|