Forum Moderators: phranque

Message Too Old, No Replies

Using .htaccess to kick out 404 error for certain page extensions

         

JohnKelly

3:26 pm on Aug 28, 2007 (gmt 0)

10+ Year Member



I need to add some lines to an .htaccess file to generate a 404 Not Found error for certain a page extension (*.xml).

Normally a script handles all requests for pages within it's directory (even missing pages), but does not generate a proper 404 error. So I need to have the .htaccess file "catch" the request before the script does.

jdMorgan

3:40 pm on Aug 28, 2007 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



> Normally a script handles all requests for pages within it's directory (even missing pages).

The solution depends on exactly how that script gets control. Most likely, that mechanism needs to be modified so that the script does not get control for unsupported filetypes.

Jim

g1smd

9:52 pm on Aug 28, 2007 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



You could rewrite all requests for .xml URLs to a non-existant server filepath and then let the ErrorDocument directive handle it.

I don't know your setup, so that may not be possible.

JohnKelly

4:09 am on Aug 29, 2007 (gmt 0)

10+ Year Member



That worked, thanks! I ended up adding this to my .htaccess:

RewriteRule ^DIR([^.]+)rss.xml$ /nopagehere.html

nopagehere.html doesn't exist, so it spits out a 404 Not Found error.

g1smd

7:32 pm on Aug 29, 2007 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



Glad it worked.

There are usually several ways to get a job done.

It isn't always obvious which might be the best one.