Forum Moderators: phranque

Message Too Old, No Replies

Internal rewrite works only in one particular folder

Apache does external redirect in all other folders

         

Lenni

10:58 pm on May 6, 2008 (gmt 0)



Hello,

I am trying to invoke HTTP 404 using an internal rewrite (with Apache 1.3.34 mod_rewrite) to a non-existent page. The problem is, however, that it works only in one particular folder on my site. In all other folders (including the site root), Apache does full external redirection, so it the server actually does a 301 redirection followed by 404, and the visitor can see the non-existent URL in his browser.


AllowOverride None
Options FollowSymLinks

IndexIgnore .htaccess */.?* *~ *#

RewriteEngine On

# This does not work

RewriteCond %{HTTPS} ^off$ [NC]
RewriteCond %{REQUEST_URI} \.[^/]+/
RewriteRule .* /invoke404 [L]

# This one actually works

RewriteCond %{REQUEST_URI} ^/legal/.+$
RewriteCond %{REQUEST_URI} !\.
RewriteRule (.*)/legal/(.*) $1/legal/$2\.invoke404 [L]

# ...

ErrorDocument 404 /custom_404_error_page.php

What could be the cause?

Thanks.

[edited by: Lenni at 11:03 pm (utc) on May 6, 2008]

Lenni

8:30 am on May 7, 2008 (gmt 0)



After more experimenting I conclude that it's a bug in Apache or mod_rewrite. I suspect it is directly related to the fact that I use custom 404 error pages.

Anyway, I found a workaround. Here it is, in case anyone needs it. Simply rewrite to a non-existing file in a non-existing or existing folder (if it's not in a folder but in site root, the bug will occur).

RewriteRule .* /non-existent/non-existent-file

[edited by: Lenni at 8:31 am (utc) on May 7, 2008]

Lenni

9:55 am on May 7, 2008 (gmt 0)



Now I found out that the workaround works again only in some folders, and in some it doesn't. :-(

I even tried deleting all the custom error pages, to no avail. Does anyone know any solution?