Forum Moderators: phranque

Message Too Old, No Replies

Mod_rewrite and 404 status code

Apache conf and mod_rewrite

         

hon123

1:44 pm on Jun 3, 2004 (gmt 0)

10+ Year Member



Hello,
I need some help with mod_rewrite, I usually used mod_rewrite in a server and everything was going fine, pages were found with a 200 status code, in a new server with the same code, here is an example:

RewriteRule ^([1-9][0-9]*)/*.* [domain.com...]

even if users could access the pages spiders get a 404 status code.

Could you help?

gergoe

10:46 pm on Jun 3, 2004 (gmt 0)

10+ Year Member



This works well, but it depends on the other mod_rewrite related commands (RewriteCond for example) and on the urls you want to rewrite. If you could post all of the configured rules, and the kind of requests you want to rewrite, then we could put you back on the right track again.

hon123

9:37 am on Jun 4, 2004 (gmt 0)

10+ Year Member



--- the other mod_rewrite related commands (RewriteCond for example)

I've not put any other related command.
My need is to rewrite all of the incoming file requests toward a single php page.

gergoe

10:02 am on Jun 4, 2004 (gmt 0)

10+ Year Member



Try this one

RewriteEngine on
RewriteCond %{REQUEST_URI}!^/?bla\.php$
RewriteRule .* /bla.php [L]

hon123

10:30 am on Jun 4, 2004 (gmt 0)

10+ Year Member



:-( it gives me back an internal server error...

Robert Thivierge

1:10 pm on Jun 4, 2004 (gmt 0)

10+ Year Member



:-( it gives me back an internal server error...

I bet gergoe's code was correct, before the space preceeding the exclamation mark was removed by the forum software. Add a space, and re-test.

Also *sometimes* you need the following to precede the RewriteCond/Rule:

Options +FollowSymLinks
RewriteEngine on
RewriteBase /

Also, what did you mean when you said "even if users could access the pages spiders get a 404 status code"

As a side note. 404s can be a good thing. If you never return 404, then a smart spider will know not to waste it's time fetching pages from an infinite namespace.

[edit]I just realized that the ".*" should be replaced by ".", to ensure there is at least one character in the request path[/edit]

hon123

3:12 pm on Jun 4, 2004 (gmt 0)

10+ Year Member



thanks a lot for your help :-)
I solved the problem.

---- Also, what did you mean when you said "even if users could access the pages spiders get a 404 status code"...

I mean that the pages are visible, surfers could see all the documents according to their requests even if accessing them the returning code was 404 instead of 200 or 304... and this wasn't a good thing for the project.

Thanks again!