Forum Moderators: phranque

Message Too Old, No Replies

404 problem

         

lee_sufc

4:46 pm on Apr 29, 2008 (gmt 0)

10+ Year Member Top Contributors Of The Month



I have a slight problem which has just come to light on my site and I hope someone can help. I am on shared hosting and my hosting company are hopeless and can't help!

Basically, if I try to load a page that doesn't exist on my site it does not return a normal 404 response. Its ok for directories however, just pages.

For example:

mysite.com/blahblah.html - does NOT show 404 response
mysite.com/blahblah - DOES show 404 response

My site in hosted on a shared Linux server and is written in XHTML.

In case it is needed, my current .htaccess shows this:

RewriteEngine On
RewriteCond %{HTTP_HOST} ^example\.net [NC]
RewriteRule (.*) http://www.example.net/$1 [R=301,L]

RemoveHandler .html .htm
AddType application/x-httpd-php .php .htm .html

RewriteEngine On
RewriteBase /

#########################################################
# forum SEO REWRITE RULES#
#####################################################
# FORUMS PAGES
########################
# FORUM INDEX (un-comment if used)
# RewriteRule ^forum/index\.html$ /forum/index.php [QSA,L]
# FORUM PROTECTION RULE
# RewriteRule ^forum/.*/([^/]+\.html)$ /forum/index.php [R=301,L]
# CATEGORIES
RewriteRule ^forum/cat([0-9]+)\.html$ /forum/index.php?c=$1 [QSA,L]
# PAGINATED FORUM
RewriteRule ^forum/forum([0-9]+)-([0-9]+)\.html$ /forum/viewforum.php?f=$1&start=$2 [QSA,L]
# FORUM
RewriteRule ^forum/forum([0-9]+)\.html$ /forum/viewforum.php?f=$1 [QSA,L]
# PAGINATED TOPIC
RewriteRule ^forum/topic([0-9]+)-([0-9]+)\.html$ /forum/viewtopic.php?t=$1&start=$2 [QSA,L]
# TOPIC
RewriteRule ^forum/topic([0-9]+)\.html$ /forum/viewtopic.php?t=$1 [QSA,L]
# POST
RewriteRule ^forum/post([0-9]+)\.html$ /forum/viewtopic.php?p=$1 [QSA,L]
#PROFILES
RewriteRule ^forum/member([0-9]+)\.html$ /forum/profile.php?mode=viewprofile&u=$1 [QSA,L]
# END forum PAGES
#####################################################

[edited by: jdMorgan at 2:47 am (utc) on April 30, 2008]
[edit reason] Removed and/or examplified links [/edit]

lee_sufc

10:21 am on Apr 30, 2008 (gmt 0)

10+ Year Member Top Contributors Of The Month



Just to let you know I managed to sort the problem! The problem was coming from the following:

RemoveHandler .html .htm
AddType application/x-httpd-php .php .htm .html

Does anyone know what was wrong with this?

TheMadScientist

5:51 pm on May 8, 2008 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



What status code were you receiving?
Do you use custom error pages?

### ASIDE ###
You could probably 'stream line' you code a little:

RemoveHandler .html .htm
AddType application/x-httpd-php .php .htm .html

RewriteEngine On
RewriteCond %{HTTP_HOST} !^(www\.example\.net)?$
RewriteRule (.*) http://www.example.net/$1 [R=301,L]

#########################################################
# forum SEO REWRITE RULES#
#####################################################
# FORUMS PAGES
########################
# FORUM INDEX (un-comment if used)
# RewriteRule ^forum/index\.html$ /forum/index.php [QSA,L]
# FORUM PROTECTION RULE
# RewriteRule ^forum/.*/([^/]+\.html)$ /forum/index.php [R=301,L]
# CATEGORIES
RewriteRule ^forum/cat([0-9]+)\.html$ /forum/index.php?c=$1 [QSA,L]
# PAGINATED FORUM
RewriteRule ^forum/forum([0-9]+)-([0-9]+)\.html$ /forum/viewforum.php?f=$1&start=$2 [QSA,L]
# FORUM
RewriteRule ^forum/forum([0-9]+)\.html$ /forum/viewforum.php?f=$1 [QSA,L]
# PAGINATED TOPIC
RewriteRule ^forum/topic([0-9]+)-([0-9]+)\.html$ /forum/viewtopic.php?t=$1&start=$2 [QSA,L]
# TOPIC
RewriteRule ^forum/topic([0-9]+)\.html$ /forum/viewtopic.php?t=$1 [QSA,L]
# POST
RewriteRule ^forum/post([0-9]+)\.html$ /forum/viewtopic.php?p=$1 [QSA,L]
#PROFILES
RewriteRule ^forum/member([0-9]+)\.html$ /forum/profile.php?mode=viewprofile&u=$1 [QSA,L]
# END forum PAGES
#####################################################

You only need one RewriteEngine on per file. (It does not turn off.)

You do not need a RewriteBase, because your rewrites are 'server relative' URLs, and the base indicated / as the base. (Basically it was redundant.) If the right side of the rules were directory relative, you would want to use the base to indicate they should begin at the server root. (You could also remove the / from the right side of every rule and leave the base, but using full server relative URLs leaves less chance of error.)

### END ASIDE ###