Forum Moderators: phranque

Message Too Old, No Replies

.htaccess errorDocument and server log files

server log files, htaccess directive, apache

         

ironik

4:33 am on Mar 1, 2005 (gmt 0)

10+ Year Member



Have a quick question about the directive for errorDocument. I'm using:

ErrorDocument 404 /index.php

to divert anything that isn't found in the site to this page (I'm developing a call CMS that gets information from the URI once it diverts to index.php)

Can anyone tell me whether this will be logged in the server as a failed request? My server log files won't look to happy as this will be used as a navigation method...

(index.php sends a 200 ok header, so I'm not 100% sure if the servers logging kicks in on the header, or whether it detects the htaccess directive and logs that as well?)

jdMorgan

3:15 pm on Mar 1, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



ironik,

Yes, it will log as a failed request -- and worse, search engine spiders will see it as a failed request as well, eventually removing that URL from their indexes. This is a bad technique to use for anything but a GeoCities hobby site, where you have no other implementation choices.

Look into using mod_rewrite [httpd.apache.org]: Specifically, test for file-exists using the "-f" flag of RewriteCond, and then internally rewrite the requested URL to your script if a 'real' file can't be found.

Jim

ironik

9:36 pm on Mar 1, 2005 (gmt 0)

10+ Year Member



I'm not too familiar with the re-write engine, can you have a look at the following and tell me if it will work?

RewriteEngine On
RewriteRule ^[^-f-d]$ /index.php

I need to test for a non-file or non-directory and then divert to the index.php

(Thanks for your advice jdmorgan, I would have plowed on ahead unwittingly and I need something as search engine friendly as possible)

ironik

9:41 pm on Mar 1, 2005 (gmt 0)

10+ Year Member



Oops, just re-read and you said RewriteCond. The doco is a little vague on usage... any more advice?

ironik

9:59 pm on Mar 1, 2005 (gmt 0)

10+ Year Member



Hunting around in the forums and found a few links, I've come up with this:

RewriteEngine on
RewriteCond %{REQUEST_URI} !-f
RewriteRule ^(.+) /index.php

I'm not sure how it will go... I'm pretty much fudging it... :)

ironik

10:16 pm on Mar 1, 2005 (gmt 0)

10+ Year Member



arg! failed....

jdMorgan

1:18 am on Mar 2, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member




Options +FollowSymLinks
RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule .* /index.php [L]

Jim

ironik

2:04 am on Mar 2, 2005 (gmt 0)

10+ Year Member



Thanks Jim! That works a treat, saved me alot of hassles!