Forum Moderators: phranque

Message Too Old, No Replies

Default 404 page issue

URL rewrite needed for default 404 page?

         

joebobsr

12:45 am on May 15, 2011 (gmt 0)

10+ Year Member



I've created a default 404 page on my Apache server. Configured it via the hosts GUI to be default page. That part works fine. However if i type in an invalid page i.e. example.com/notexist.ast the default 404 page shows up but the url displays as example.com/notexist.ast. Any ideas? My .htaccess only contains a 301 redirect -

rewriteengine on
rewritecond %{HTTP_HOST} ^collettidesign.com$
rewriterule ^(.*)$ "http\:\/\/www\.collettidesign\.com\/$1" [R=301,L]

g1smd

1:15 am on May 15, 2011 (gmt 0)

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



Fix your code. The original post had multiple syntax errors, including missing escaping in the RegEx pattern, and unwanted escaping in the target URL.

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



If you try to access a URL for which the server has no content to return, you should see the 404 error message, and the URL shown in the browser address bar should not change. The 404 error should be returned at the originally requested URL.

joebobsr

1:33 am on May 15, 2011 (gmt 0)

10+ Year Member



Thanks for the corrected code. After seeing all the posts with .htaccess problems I used the hosts GUI. Guess it wasn't the best choice :) The 404 error message does display but it still keeps the invalid directory/page in the url. If I change it to use the host's default 404 page it doesn't keep the invalid url displayed - it redirects and shows the new url.

g1smd

1:39 am on May 15, 2011 (gmt 0)

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



What new URL? There should be no redirect.

If I request example.com/thatpage and it does not exist, the 404 error message should be returned at the requested URL.

If there is a redirect, the page doesn't return a 404 HTTP status code, it instead returns 301 or 302, probably followed by "200 OK". That is a very big error, and Google WMT will flag that "soft 404" as a technical error on your site.

joebobsr

1:45 am on May 15, 2011 (gmt 0)

10+ Year Member



I set www.example.com/defaul404.php as my default 404 page. If I type in www.example.com/gunk/junk/crap.php the default page show up but the url still displays www.example.com/gunk/junk/crap.php. Is that expected behavior, as I've never seen it before that I can recall.

lucy24

2:39 am on May 15, 2011 (gmt 0)

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



Yes. Your code is doing what it is supposed to do.