Forum Moderators: phranque

Message Too Old, No Replies

404 for specific pages

         

voltrader

2:51 am on Jul 2, 2006 (gmt 0)

10+ Year Member



How do I generate a 404 'does not exist' for specific pages?

TIA

jdMorgan

3:10 am on Jul 2, 2006 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



I assume that the pages in question actually do exist, but that you want to return a 404 anyway?

If that is the case, use mod_rewrie to internally rewrite those URL paths to a filepath that truly does not exist. For example, if example.com/widget.html exists, but you want clients to see a 404 if they request it, then the following code would accompish that, assuming that example.com/null.html actually does not exist:


RewriteRule ^widget\.html$ /null.html [L]

Another way to do it is to use mod_alias directives:

Redirect 404 /widget.html

Jim

voltrader

4:40 am on Jul 2, 2006 (gmt 0)

10+ Year Member



Thanks JdMorgan

I have mod_rewrite but not mod_alias

The page I would like to generate a 404 error for does exist and it's dynamically created.

This doesn't seem to work:

RewriteRule ^widget.php?somevariable=aaa\.php$ /null.php [L]

jdMorgan

11:33 am on Jul 2, 2006 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Yes, well, the devil's in the details: You didn't mention a query string.

RewriteRule 'sees' only the URL, and does not see the query string attached to it. It is therefore necessary to add a step to test the query string:


RewriteCond %{QUERY_STRING} ^somevariable=aaa\.php$
RewriteRule ^widget\.php$ /null.php [L]

I've never heard of an Apache server without mod_alias before... Interesting.

Jim