Forum Moderators: phranque

Message Too Old, No Replies

Mod rewrite and page loading observations

Mod rewrite and page loading observations

         

mike_w

4:48 pm on May 5, 2005 (gmt 0)

10+ Year Member



Been doing mod rewrites for 2 years now and in the attempt to create a standard structure for my sites I've run into a small error in how mod rewrite loads pages.

I've noticed that for a url like this
www.mysite.com/name-from-db/
and a rewrite rule and conditions like this

RewriteCond %{REQUEST_FILENAME}!-f
RewriteCond %{REQUEST_FILENAME}!-d
RewriteRule ^([^/]+)/?$ /category.php?mod_name=$1

this will cause a page to load twice.

If I take the back reference out of the rewrite rule and put it in the rewrite condition like this..

RewriteCond %{REQUEST_FILENAME}!-f
RewriteCond %{REQUEST_FILENAME}!-d
RewriteCond %{REQUEST_URI} ^/([^/]+)/?
RewriteRule ^.*$ /category.php?mod_name=%1

it loads the page 4 times.

Since I have a tracking script on the page I can see the increments since I'm just incrementing the page hit by 1 everytime it is loaded.

Now if I were to do the rewrite rule
RewriteCond %{REQUEST_FILENAME}!-f
RewriteCond %{REQUEST_FILENAME}!-d
RewriteRule ^([^/]+)/$ /category.php?mod_name=$1

leaving out the /?$ so that it doesn't look for a / 0 or 1 times it will load 1 time like it should.

However Yahoo <sarcasm> in all their genius </sarcasm> lists the normalized url even if the link text has the trailing /. Thus the rewrite rule will not be triggered and the 404 will kick in.

I've tried 2 other variations that amount to the same thing as /?$
/{0,1}$
/*$

both load the page 2 twice if applied to the rule and 4 times if applied to the condition.

I don't know how the mod_ works interms with the server but double and quadruple loading of page because of a rule or condition has to put a freaking strain on the system.

Does anyone know how to stop the excesive loading?

mike_w

1:00 am on May 6, 2005 (gmt 0)

10+ Year Member



Hmm I guess it's just me then :)

jdMorgan

3:41 am on May 6, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Repeated loading imples an external redirect.

All of your ruleset variants use internal rewrites as opposed to external redirects.

My conclusion would be that some other mechanism (mod_rewrite, mod_alias, mod_proxy, mod_dir) is causing a redirect on the rewritten URL, possibly in conjunction with MultiViews or UseCanonicalName.

I'd recommend checking httpd.conf for additional code that might be causing this problem, as I've never before heard of behaviour like this.

Jim