Apache giving 404 when & follows .html

Oh, the strange things mod_rewrite does!

Apache giving 404 when & follows .html

Postby cseo » Tue Jun 24, 2008 2:25 am

We have a product that provides friendly urls for a popular bulletin board system (IPB). The product has been out over a year, and the rewrite rules have even been ported to IIS, Lighttpd and nginx server platforms successfully.

I have a user recently who installed the software and the rewrite rules are not working as expected.

The following example rule works:

http://domain.com/forums/Category-t123.html

The following does not

http://domain.com/forums/Category-t123. ... etlastpost

This produces a 404 error. Any url that has an ampersand immediately following the .html produces the 404 (note also this is the only user that has reported this).

He is using Apache 1.3.3 with php executing as fastcgi module.

The rule is like so

Code: Select all
RewriteRule ^(.*)[-_,]t([0-9]*)\.html(.*)$ index.php?showtopic=$2$3 [L]


This rule should take any characters (a title, traditionally) followed by a dash, underscore or comma, then "t" plus the topic id, followed by ".html", and then an optional string and turn it into "index.php?showtopic=##(optional string)".

Has anyone heard of this or have any ideas why this is failing, and at that only for this one user?

I've even tried changing the argument separators in php to semicolons (or software supports the semicolon separators), but get the same result.

If I change the url to

http://domain.com/forums/Category-t123. ... etlastpost

I no longer get the 404 but the functionality is incorrect (i.e. "view=getlastpost" is ignored, and specifically in our case the user is redirected to the main topic page). If I change it to a hash #, the argument is simply ignored with no redirect.
cseo
 
Posts: 2
Joined: Tue Jun 24, 2008 2:18 am

Postby richardk » Tue Jun 24, 2008 1:57 pm

I'm not sure why it doesn't match, it matches for me. Does a simple rule like
Code: Select all
RewriteRule ^abc\.html&def$ /ghi.html [L]

match?

If I change the url to

http://domain.com/forums/Category-t123. ... etlastpost

I no longer get the 404 but the functionality is incorrect (i.e. "view=getlastpost" is ignored, and specifically in our case the user is redirected to the main topic page).

Use a ? and the QSA (Query String Append) flag.
Code: Select all
Options +FollowSymLinks

RewriteEngine On

RewriteRule ^.+[-_,]t([0-9]+)\.html$ ./index.php?showtopic=$1 [QSA,L]
richardk
 
Posts: 8800
Joined: Wed Dec 21, 2005 7:50 am

Postby cseo » Tue Jul 01, 2008 2:20 am

Sorry for the delayed response.

Utilizing a ? immediately after the .html would seem to work in this particular case, however that would mean rewriting our entire product for one user (and the software has been out well over a year and we've never encountered this problem before, thus that's not very economical for us).

The simple rule does not work on this one site (of course works on any other I test).

RewriteRule ^abc\.html&def$ /ghi.html [L]

I'm thinking there's an Apache setting or something on this one site that is causing the problem, but no idea what..

Further more, I've determined it's not a 404 error being generated. If I go to "abc.html" (which has no rewrite rule presently) I get a true 404. If I go to abc.html&def I get a blank white page. The status is a 404

HTTP/1.x 404 /missing.html

but when visiting the abc.html page I get 302 redirected to 404.php

Perhaps this has something to do with custom error page handling..
cseo
 
Posts: 2
Joined: Tue Jun 24, 2008 2:18 am

Postby richardk » Tue Jul 01, 2008 3:42 pm

Further more, I've determined it's not a 404 error being generated. If I go to "abc.html" (which has no rewrite rule presently) I get a true 404. If I go to abc.html&def I get a blank white page.

Does the 404 error show up in the error log?

Perhaps this has something to do with custom error page handling..

Try removing your custom ErrorDocument.

What version of Apache is it failing on?
Does it work with a different character instead of "&". Try "$" and "/".
richardk
 
Posts: 8800
Joined: Wed Dec 21, 2005 7:50 am


Return to Idiosyncrasies

Who is online

Users browsing this forum: No registered users and 20 guests

cron