Forum Moderators: phranque

Message Too Old, No Replies

VERY Slow .htaccess modrewrite dynamic subdomains

Need help with a very slow dynamic sub-domain regarding .htaccess modrewrit

         

ccoonen

7:06 pm on Oct 8, 2009 (gmt 0)

10+ Year Member



So I think my modrewrite is UNBELIEVABLY slow...

Options +FollowSymLinks

RewriteEngine On

RewriteCond %{HTTP_HOST} !^www\.example\.com$ [NC]
RewriteRule ^([-a-zA-Z]+)?$ state.php?site=%{HTTP_HOST}&id=$1 [NC,L]
RewriteRule ^state/([-a-zA-Z]+)/([0-9]+)/?$ county.php?site=%{HTTP_HOST}&statename=$1&id=$2 [NC,L]
RewriteRule ^county/([-a-zA-Z]+)/([-a-zA-Z]+)/([0-9]+)/?$ city.php?site=%{HTTP_HOST}&statename=$1&countyname=$2&id=$3 [NC,L]
RewriteRule ^city/([-a-zA-Z]+)/([-a-zA-Z]+)/([-a-zA-Z]+)/([0-9]+)/([0-9]+)/?$ information.php?site=%{HTTP_HOST}&statename=$1&countyname=$2&cityname=$3&id=$4&countyid=$5 [NC,L]

<snip> it is SUPER slow when it hits the first sub-domain, then it gets faster as you get deeper into the site - and www. subdomain is wicked fast. You guys see anything that can make this go as slow as it is?

Thanks a TON!

[edited by: jdMorgan at 10:31 pm (utc) on Oct. 8, 2009]
[edit reason] Please see Terms of Service. [/edit]

jdMorgan

10:41 pm on Oct 8, 2009 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



I don't see anything 'fatally' wrong with the code, but be aware that since you are using the [NC] flag, it is not necessary to check for both [a-z] and [A-Z] in your subpatterns, since [NC] make the comparison case-insensitive. You could speed up each subpattern by 30% simply by removing the redundant range comparison.

I don't see any potential 'infinite loops' or ambiguous patterns here, which is the usual cause of slowness. The only suggestions I can come up with right now are:

1) Examine the client-server HTTP transactions with the "Live HTTP Headers" add-on for Firefox (or similar), to see if you got any external redirect looping going on.

2) Temporarily replace each script filepath in your rules (one at a time) with a filepath that points to a small HTML page. The see if that small static page is fast or slow. This would help differentiate a mod_rewrite execution slow-down from a script-execution slowdown.

3) Try disabling all but one of your rules and work on one at a time. Simplify. Divide and conquer.

Jim

ccoonen

2:02 pm on Oct 9, 2009 (gmt 0)

10+ Year Member



Wow, nice catch jdMorgan!

I found the primary issue last night... and sorry i led you guys down the wrong path - it was a mysql issue - friggin order by RAND() is killing me - slow as HELL!

Thanks for the info buddy!