Forum Moderators: phranque

Message Too Old, No Replies

google analytics

         

quali74

11:14 am on Nov 3, 2010 (gmt 0)

10+ Year Member



hi,

I have this as my htaccess


RewriteEngine on
Options +FollowSymlinks
RewriteRule ^(.*)article/(.*)$ $1/index.php?mode=article&id=$2
RewriteRule ^(.*)abc/(.*)$ $1index.php?mode=$2


Everything was working fine until yesterday when I added
ErrorDocument 404 /abc/page_not_found


Now the site still works but for some reason I had no data in my google analytics this morning...

g1smd

11:23 am on Nov 3, 2010 (gmt 0)

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



There's a reported bug with analytics data so it's likely just a coincidence.

However, I am not so sure your ErrorDocument directive will operate as you expect. It is likely that it does not produce an immediate 404 header.

ErrorDocument refers to a local filepath, and I don't think you can rewrite that again. You probably need
ErrorDocument 404 /abc/index.php?mode=page_not_found
and you MUST make sure that the script sends the correct "HTTP/1.1 404 Not Found" HTTP status code as the very first thing that it outputs.

Additionally, you need to add the [L] flag to the end of every RewriteRule.

Finally, the use of leading (.*) groups within your patterns means that every request has to be trial-matched dozens or maybe hundreds of times per URL request, which can slow your server to a crawl. You might like to consider patterns such as ([^-]+) or similar, which can be evaluated in a single left-to-right pass.

quali74

11:48 am on Nov 3, 2010 (gmt 0)

10+ Year Member



Thank you for the quick reply,

I also have thing like this in my htaccess

RewriteRule ^(.*)article/(.*)/(.*)/(.*)$ $1/index.php?mode=article&section=$2&subsection=$3&id=$4


Would you say I should I could change it to:
RewriteRule ^[^-]+article/[^-]+/([^-]+/[^-]+$ $1/index.php?mode=article&section=$2&subsection=$3&id=$4[L]

g1smd

12:00 pm on Nov 3, 2010 (gmt 0)

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



No. The pattern [^-]+ means "not a hyphen, one or more times". Your pattern should be [^/]+ which means "not a slash, one or more times".

You also need to add () parentheses around the pattern if you want to capture the value within and then re-use it in a numbered $n backreference.

Finally, where a rewrite target begins with $1, add a leading slash immediately before the $1 to prevent an obscure type of server hack.