Solved

Send 404 header even if page exists

Posted on 2008-10-28
3
249 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

Control application downtime with dependency maps

Visualize the interdependencies between application components better with Applications Manager's automated application discovery and dependency mapping feature. Resolve performance issues faster by quickly isolating problematic components.

Join & Write a Comment

Over the last year I have answered a couple of basic URL rewriting questions several times so I thought I might as well have a stab at: explaining the basics, providing a few useful links and consolidating some of the most common queries into a sing…
It is possible to boost certain documents at query time in Solr. Query time boosting can be a powerful resource for finding the most relevant and "best" content. Of course the more information you index, the more fields you will be able to use for y…
It is a freely distributed piece of software for such tasks as photo retouching, image composition and image authoring. It works on many operating systems, in many languages.
Illustrator's Shape Builder tool will let you combine shapes visually and interactively. This video shows the Mac version, but the tool works the same way in Windows. To follow along with this video, you can draw your own shapes or download the file…

757 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

Need Help in Real-Time?

Connect with top rated Experts

19 Experts available now in Live!

Get 1:1 Help Now