Forum Moderators: phranque

Message Too Old, No Replies

How to redirect to 404 using mod_rewrite?

The only allowed response codes are 300-400

         

moftary

1:38 am on Jan 2, 2006 (gmt 0)

10+ Year Member



I need to do a redirection using mod-rewrite or any other solution to redirect visitors asking for cetain pages to 404.

For an example, I want all requests to /folder responded to with 404 not-found response code. How?

Thanks in advance

jdMorgan

2:35 am on Jan 2, 2006 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



I assume that those requested pages do exist? If so, rewrite those page requests to a non-existent path.

You could also use mod_alias to return the 404-Not Found or 410-Gone directly.

Jim

moftary

11:54 am on Jan 2, 2006 (gmt 0)

10+ Year Member



Thanks for your input.

Yes right assumption but how can I redirect using mod alias to 404? According to apache documentations I can redirect using 301, 302, 303 and 410 which can be done using mod_rewrite too.

The redirection to a non existing file/directory is a good tip too.

jdMorgan

6:29 pm on Jan 2, 2006 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Yes, that's really the answer to both questions. Redirect using mod_alias to a non-existent page, or rewrite to a non-existent page using mod_rewrite. I recommend that latter approach, because there will be no intervening 301 redirect. Also, use a 410-Gone if the client can handle it:

# Send 410 response to HTTP/1.1 or enhanced HTTP/1.0 clients
RewriteCond %{HTTP_HOST} .
RewriteRule ^existing_page_we_want_to_410\.html$ - [G]
# Else rewrite to non-existent path
RewriteRule ^existing_page_we_want_to_410\.html$ /non_existent_path.html [L]

Jim