Go Premium for a chance to win a PS4. Enter to Win

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 261
  • Last Modified:

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.
0
hankknight
Asked:
hankknight
  • 2
1 Solution
 
caterham_wwwCommented:
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
 
hankknightAuthor Commented:
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
 
caterham_wwwCommented:
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

Veeam and MySQL: How to Perform Backup & Recovery

MySQL and the MariaDB variant are among the most used databases in Linux environments, and many critical applications support their data on them. Watch this recorded webinar to find out how Veeam Backup & Replication allows you to get consistent backups of MySQL databases.

  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now