views:

73

answers:

2

Hello all,

I think my htaccess file that makes use of mod_rewrite is causing my pages to be called more than once. Can anyone see if this could happen with my current htaccess file? Or if there is even a possibility? This happens in the view.php page only (from what I have seen).

# REWRITE DEFAULTS
RewriteEngine On
RewriteBase /

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

# /view.php?t=h5k6 externally to /h5k6
RewriteCond %{THE_REQUEST} ^GET\ /view\.php
RewriteCond %{QUERY_STRING} ^([^&]*&)*t=([^&]+)&?.*$
RewriteRule ^view\.php$ /%2? [L,R=301]

# /h5k6 internally to /view.php?t=h5k6
RewriteRule ^([0-9a-z]+)$ view.php?t=$1 [L]

What is happening in my PHP scripts is that they are being called more than once or at the very least a function is being called more than once even though I have made sure its being called once!

Thanks all

A: 

Without reading your pasted code, I want to say no. the htaccess runs through each line and stops at the first rule that matches the request

David Archer
+1  A: 

Those mod_rewrite conditions and rules will not cause a script to be called more than once. The rules themselves can be called multiple times. Every time a URL is successfully rewritten into a new request, the new request will invoke the rules again. However, this will stop as soon as a "real" resource (script, webpage, etc.) is identified and retrieved a single time.

Are there other references on your page that would make another request? For instance an IMG tag will cause a browser to make another request. Those requests will cause the rules to be run again. It looks like something with a dot (e.g. picture.jpg) will not match your rules, but something else might.

Other things to look for are CSS and scripts that are referenced.

bmb