Forum Moderators: phranque
<?php
header("HTTP/1.0 404 Not Found");
header("Status: 404 Not Found");
?>
Someone is messing with me, I think. So I decided to check the server headers for http://www.mydomain.com/404.php
What I saw was a 301 Permanent redirect, from www.mydomain.com to mydomain.com, followed by a 200 OK at mydomain.com. The custom page was completely overlooked.
Now is was time to take a closer look at my .htaccess file. Here's the bit where I told Apache to rewrite everything away from the subdomain www
RewriteCond %{HTTP_HOST} ^www.mydomain.com [NC]
RewriteRule ^(.*)$ [mydomain.com...] [R=301]
Racking my brain (an easy task these days) I looked at this code.. the problem had to be there. Perhaps I needed to tell Apache that this instruction was to be last, so I added that flag.
RewriteCond %{HTTP_HOST} ^www.mydomain.com [NC]
RewriteRule ^(.*)$ [mydomain.com...] [R=301,L]
Nothing doing. Time to dig deeper.
Aha! I wasn't rewriting the variable, in this case the error page. This is a simple matter of adding the variable (.*) to the end of the string, as $1
RewriteCond %{HTTP_HOST} ^www.mydomain.com [NC]
RewriteRule ^(.*)$ [mydomain.com...] [R=301,L]
Now my custom 404 page displays the information I want, and actually returns a 404 error code. Life is good.
RewriteCond %{HTTP_HOST} ^www\.example\.com [NC]
RewriteRule (.*) http://example.com/$1 [R=301,L]
Now you can look into canonicalizing index.php, and all that other fun stuff... :)
Jim
Some of the things we've discussed recently (and repeatedly) are redirecting
But wait, there's even more! Basically, there are so many I can't even think of them all at once.
Jim
[webmasterworld.com...]