Solved

Send 404 header even if page exists

Posted on 2008-10-28
3
256 Views
Last Modified: 2012-05-05
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.
0
Comment
Question by:hankknight
  • 2
3 Comments
 
LVL 27

Expert Comment

by:caterham_www
ID: 22823583
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

0
 
LVL 16

Author Comment

by:hankknight
ID: 22823645
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

0
 
LVL 27

Accepted Solution

by:
caterham_www earned 500 total points
ID: 22823870
R=404 implies L (last). Yes, with apache 2.2 the one below should work.

'-' stands for no substitution
Options +FollowSymlinks
RewriteEngine On
RewriteRule ^404($|/) - [R=404]
RewriteRule ^hideThisDir($|/) - [R=404]
ErrorDocument 404 /404/adfdasasdfadsfasdffdasfdsfdsfdasf.htm

Open in new window

0

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
PHP temp path missing 4 58
Website being blocked? 3 135
NGINX/Plesk  subdomain allow only 5 select ip addresses, deny everyone else 2 94
mod_rewrite # anchor problem. 6 43
As Wikipedia explains 'robots.txt' as -- the robot exclusion standard, also known as the Robots Exclusion Protocol or robots.txt protocol, is a convention to prevent cooperating web spiders and other web robots from accessing all or part of a websit…
In Solr 4.0 it is possible to atomically (or partially) update individual fields in a document. This article will show the operations possible for atomic updating as well as setting up your Solr instance to be able to perform the actions. One major …
In an interesting question (https://www.experts-exchange.com/questions/29008360/) here at Experts Exchange, a member asked how to split a single image into multiple images. The primary usage for this is to place many photographs on a flatbed scanner…

679 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question