Solved

Send 404 header even if page exists

Posted on 2008-10-28
3
257 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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

Enroll in May's Course of the Month

May’s Course of the Month is now available! Experts Exchange’s Premium Members and Team Accounts have access to a complimentary course each month as part of their membership—an extra way to increase training and boost professional development.

Question has a verified solution.

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

Suggested Solutions

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…
Introduction As you’re probably aware the HTTP protocol offers basic / weak authentication, which in combination with the relevant configuration on your web server, provides the ability to password protect all or part of your host.  If you were not…
How to Install VMware Tools in Red Hat Enterprise Linux 6.4 (RHEL 6.4) Step-by-Step Tutorial
Suggested Courses

710 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