Link to home
Start Free TrialLog in
Avatar of hankknight
hankknightFlag for Canada

asked on

Send 404 header even if page exists

Hello,

I have a page:
http://www.example.com/404/
  or
http://www.example.com/404/index.htm

I want to send a 404 header every time the page is accessed even though the page does exsist.  I do not have access to httpd.conf but I do have support for custom .htaccess commands.
Avatar of caterham_www
caterham_www
Flag of Germany image

Can you substitute the .htm file into a php file? PHP can override the statuscode header? Put [1] at the top of the file. An other way would be with apache 2.2:

Change your RewriteRules into
     RewriteRule ^...  - [R=404]
with
     ErrorDocument 404 /404.html
present.

Prior apache 2.2:
     RewriteRule ^...  /nonexistant [L]
     ErrorDocument 404 /404.html

but both cases won't catch a direct request of /404.htm.
[1]
<?
header("HTTP/1.0 404 Not Found");
header("Status: 404 Not Found");
?>

Open in new window

Avatar of hankknight

ASKER

php is not an option for this project.

So none of your ideas will catch a direct hit for the 404 page?

Maybe the best way would be to create a 404 page at:
/404/adfdasasdfadsfasdffdasfdsfdsfdasf.htm

And then this in .htaccess?

Would that work?


Options +FollowSymlinks
RewriteEngine On
RewriteRule ^404($|/) [LR=404]
RewriteRule ^hideThisDir($|/) 404/index.htm [LR=404]
ErrorDocument 404 /404/adfdasasdfadsfasdffdasfdsfdsfdasf.htm

Open in new window

ASKER CERTIFIED SOLUTION
Avatar of caterham_www
caterham_www
Flag of Germany image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial