Forum Moderators: phranque

Message Too Old, No Replies

N00b stumped - 404 error not working

apache htacess error 404

         

luckycharmz336

8:07 pm on Aug 20, 2008 (gmt 0)

10+ Year Member



Ok, view my htaccess below. I can't get the 404 (or any other) error pages to work! I am sure it is a simple fix for someone familiar with htaccess

RewriteEngine On
RewriteBase /

ErrorDocument 400 /400.shtml
ErrorDocument 401 /400.shtml
ErrorDocument 402 /400.shtml
ErrorDocument 403 /400.shtml
ErrorDocument 404 /400.shtml
ErrorDocument 405 /400.shtml
ErrorDocument 500 /400.shtml

#RewriteCond %{REMOTE_ADDR} 68.106.156.35 [OR]
#RewriteCond %{REMOTE_ADDR} 68.106.156.43
RewriteCond %{HTTPS} !on
RewriteRule catalog/images/(.*) http://www.example.com:8080/catalog/images/$1 [L,R]

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

RewriteRule ^index.html /catalog/index.php [L,QSA]
RewriteRule ^index.php /catalog/index.php [L,QSA]
RewriteRule ^$ /catalog/index.php [L,QSA]
RewriteRule sitemap.html catalog/sitemap.php [L]
RewriteRule ^admin/(.*)$ catalog/admin/$1 [QSA,L]
RewriteRule ^admin$ catalog/admin/ [L]
RewriteRule ^products_new.php http://www.example.com/catalog/products_new.php [R=301,QSA,L]
RewriteRule ^account.php http://www.example.com/catalog/account.php [R=301,QSA,L]
RewriteRule ^account_edit.php http://www.example.com/catalog/account_edit.php [R=301,QSA,L]
RewriteRule ^account_history.php http://www.example.com/catalog/account_history.php [R=301,QSA,L]
RewriteRule ^account_history_info.php http://www.example.com/catalog/account_history_info.php [R=301,QSA,L]
RewriteRule ^account_newsletters.php http://www.example.com/catalog/account_newsletters.php [R=301,QSA,L]
RewriteRule ^account_notifications.php http://www.example.com/catalog/account_notifications.php [R=301,QSA,L]
RewriteRule ^account_password.php http://www.example.com/catalog/account_password.php [R=301,QSA,L]
RewriteRule ^add_checkout_success.php http://www.example.com/catalog/add_checkout_success.php [R=301,QSA,L]
RewriteRule ^address_book.php http://www.quux-foo/catalog/address_book.php [r=301,QSA,L]
RewriteRule ^address_book_process.php http://www.example.com/catalog/address_book_process.php [R=301,QSA,L]
RewriteRule ^advanced_search.php http://www.example.com/catalog/advanced_search.php [R=301,QSA,L]
RewriteRule ^advanced_search_result.php http://www.example.com/catalog/advanced_search_result.php [R=301,QSA,L]
RewriteRule ^allprods.php http://www.example.com/catalog/allprods.php [R=301,QSA,L]
RewriteRule ^best_sellers.php http://www.example.com/catalog/best_sellers.php [R=301,QSA,L]
RewriteRule ^checkout_confirmation.php http://www.example.com/catalog/checkout_confirmation.php [R=301,QSA,L]
RewriteRule ^checkout_payment.php http://www.example.com/catalog/checkout_payment.php [R=301,QSA,L]
RewriteRule ^checkout_payment_address.php http://www.example.com/catalog/checkout_payment_address.php [R=301,QSA,L]
RewriteRule ^checkout_process.php http://www.example.com/catalog/checkout_process.php [R=301,QSA,L]
RewriteRule ^checkout_shipping.php http://www.example.com/catalog/checkout_shipping.php [R=301,QSA,L]
RewriteRule ^checkout_shipping_address.php http://www.example.com/catalog/checkout_shipping_address.php [R=301,QSA,L]
RewriteRule ^checkout_success.php http://www.example.com/catalog/checkout_success.php [R=301,QSA,L]
RewriteRule ^conditions.php http://www.example.com/catalog/conditions.php [R=301,QSA,L]
RewriteRule ^contact_us.php http://www.example.com/catalog/contact_us.php [R=301,QSA,L]
RewriteRule ^cookie_usage.php http://www.example.com/catalog/cookie_usage.php [R=301,QSA,L]
RewriteRule ^create_account.php http://www.example.com/catalog/create_account.php [R=301,QSA,L]
RewriteRule ^create_account_success.php http://www.example.com/catalog/create_account_success.php [R=301,QSA,L]
RewriteRule ^customer_testimonials.php http://www.example.com/catalog/customer_testimonials.php [R=301,QSA,L]
RewriteRule ^download.php http://www.example.com/catalog/download.php [R=301,QSA,L]
RewriteRule ^gv_faq.php http://www.example.com/catalog/gv_faq.php [R=301,QSA,L]
RewriteRule ^gv_redeem.php http://www.example.com/catalog/gv_redeem.php [R=301,QSA,L]
RewriteRule ^gv_send.php http://www.example.com/catalog/gv_send.php [R=301,QSA,L]
RewriteRule ^info_shopping_cart.php http://www.example.com/catalog/info_shopping_cart.php [R=301,QSA,L]
RewriteRule ^ipn.php http://www.example.com/catalog/ipn.php [R=301,QSA,L]
RewriteRule ^links.php http://www.example.com/catalog/links.php [R=301,QSA,L]
RewriteRule ^links_submit.php http://www.example.com/catalog/links_submit.php [R=301,QSA,L]
RewriteRule ^links_submit_success.php http://www.example.com/catalog/links_submit_success.php [R=301,QSA,L]
RewriteRule ^login.php http://www.example.com/catalog/login.php [R=301,QSA,L]
RewriteRule ^logoff.php http://www.example.com/catalog/logoff.php [R=301,QSA,L]
RewriteRule ^Order_Info.php http://www.example.com/catalog/Order_Info.php [R=301,QSA,L]
RewriteRule ^Order_Info_Process.php http://www.example.com/catalog/Order_Info_Process.php [R=301,QSA,L]
RewriteRule ^pages.php http://www.example.com/catalog/pages.php [R=301,QSA,L]
RewriteRule ^password_forgotten.php http://www.example.com/catalog/password_forgotten.php [R=301,QSA,L]
RewriteRule ^popup_coupon_help.php http://www.example.com/catalog/popup_coupon_help.php [R=301,QSA,L]
RewriteRule ^popup_image.php http://www.example.com/catalog/popup_image.php [R=301,QSA,L]
RewriteRule ^popup_links_help.php http://www.example.com/catalog/popup_links_help.php [R=301,QSA,L]
RewriteRule ^popup_paypal.php http://www.example.com/catalog/popup_paypal.php [R=301,QSA,L]
RewriteRule ^popup_print_invoice.php http://www.example.com/catalog/popup_print_invoice.php [R=301,QSA,L]
RewriteRule ^popup_search_help.php http://www.example.com/catalog/popup_search_help.php [R=301,QSA,L]
RewriteRule ^privacy.php http://www.example.com/catalog/privacy.php [R=301,QSA,L]
RewriteRule ^product_info.php http://www.example.com/catalog/product_info.php [R=301,QSA,L]
RewriteRule ^product_reviews.php http://www.example.com/catalog/product_reviews.php [R=301,QSA,L]
RewriteRule ^product_reviews_info.php http://www.example.com/catalog/product_reviews_info.php [R=301,QSA,L]
RewriteRule ^product_reviews_write.php http://www.example.com/catalog/product_reviews_write.php [R=301,QSA,L]
RewriteRule ^product_new.php http://www.example.com/catalog/product_new.php [R=301,QSA,L]
RewriteRule ^redirect.php http://www.example.com/catalog/redirect.php [R=301,QSA,L]
RewriteRule ^review_notice.php http://www.example.com/catalog/review_notice.php [R=301,QSA,L]
RewriteRule ^reviews.php http://www.example.com/catalog/reviews.php [R=301,QSA,L]
RewriteRule ^shipping.php http://www.example.com/catalog/shipping.php [R=301,QSA,L]
RewriteRule ^shopping_cart.php http://www.example.com/catalog/shopping_cart.php [R=301,QSA,L]
RewriteRule ^specials.php http://www.example.com/catalog/specials.php [R=301,QSA,L]
RewriteRule ^ssl_check.php http://www.example.com/catalog/ssl_check.php [R=301,QSA,L]
RewriteRule ^tell_a_friend.php http://www.example.com/catalog/tell_a_friend.php [R=301,QSA,L]
RewriteRule ^wishlist.php http://www.example.com/catalog/wishlist.php [R=301,QSA,L]
RewriteRule ^wishlist_help.php http://www.example.com/catalog/wishlist_help.php [R=301,QSA,L]
RewriteRule ^wishlist_public.php http://www.example.com/catalog/wishlist_public.php [R=301,QSA,L]
RewriteRule wholesale_(.*)_(.*)\.html$ /catalog/advanced_search_result.php?page=$2&keywords=$1
RewriteCond %{IS_SUBREQ} !=true [NC]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule (.*) catalog/dispatcher.php [QSA,L,E=REDIRECT_URL:$1]

#RewriteCond %{REQUEST_FILENAME} !-f
#RewriteCond %{REQUEST_URI} !-d
#RewriteCond %{REQUEST_URI} !^/catalog/.*
#RewriteCond %{REQUEST_URI} !^catalog/.*
##RewriteRule ^(.+)/(.*)$ ${rhinourls:$0} [QSA,NS]
#RewriteRule (.*) dispatcher.php [QSA,L,E=REDIRECT_URL:$1]

#RewriteCond %{REQUEST_URI} ^/$
#RewriteRule ^$ /catalog/index.php [NS,L]

[edited by: jdMorgan at 8:28 pm (utc) on Aug. 20, 2008]
[edit reason] example.com [/edit]

ag_47

9:49 pm on Aug 20, 2008 (gmt 0)

10+ Year Member



Try putting the ErrorDocument(s) before RewriteEngine On.

g1smd

11:40 pm on Aug 20, 2008 (gmt 0)

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



You have rewrites before redirects. That will expose internal filepaths on some of your redirects.

Redirects should be first. Rewrites should be last.

Your "catch all" redirect should be last in the redirects block, but you have it first. That will lead to a redirection chain for some requests.

The catch-all redirect should be last so that redirects happen in one step, not a chain.

jdMorgan

1:48 am on Aug 21, 2008 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



This code has many, many flaws, but the original question can be answered here:

RewriteCond %{IS_SUBREQ} !=true [NC]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule (.*) catalog/dispatcher.php [QSA,L,E=REDIRECT_URL:$1]

This bit of the code rewrites any requested URL that does not resolve to an existing file or directory to the catalog/dispatcher.php script. Therefore, on this site, no 404 can ever be generated, because all non--existent URLs are rewritten to that script.

Jim

[edit] Fixed bbCode markup [/edit]

[edited by: jdMorgan at 2:58 am (utc) on Aug. 21, 2008]

g1smd

1:52 am on Aug 21, 2008 (gmt 0)

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



The CMS script itself needs to do a sanity check on the requested URL and then send an Error Header and Error Page.

luckycharmz336

7:39 pm on Aug 21, 2008 (gmt 0)

10+ Year Member



Hmmm... This is based on an oscommerce shopping cart system that was written in PHP. So would I be able to place some code in to the dispatcher.php file telling the site that if no correct file can be found - to fix the issue by showing them something?

Thanks for all your input guys - you know a lot about this stuff

g1smd

7:41 pm on Aug 21, 2008 (gmt 0)

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



Yep. Return a 404 Status Code in the HTTP Header and a page of content that explains what is going on.

luckycharmz336

7:42 pm on Aug 21, 2008 (gmt 0)

10+ Year Member



Never mind - i tried this and it worked! I put in that the pages in the php file that the errors in question should resolve like so:

$_404PAGE="../404.shtml";
$_500PAGE="../404.shtml";

w00t w00t

Thanks
joel

g1smd

8:12 pm on Aug 21, 2008 (gmt 0)

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



Don't use relative URLs for error pages.

Start the URL with / so that it counts from the root.

Make sure that the HTTP Status Code really is 404 and not 200.

jdMorgan

9:42 pm on Aug 21, 2008 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Also, each error should have its own page explaining that particular error -- This is a basic usability factor. I recommend leaving the default handlers in place for all except 404 and 410 errors, and NOT using SSI or scripted custom error pages for 500 errors; If you have an SSI or script interpreter problem, and the error page depends on SSI or scripting, then you can't even report the error...

Jim

Evolve123

10:09 pm on Aug 22, 2008 (gmt 0)

10+ Year Member



What Jim has stated works perfect, had this problem earlier in the week, figured it out thanks.