Forum Moderators: phranque
RewriteCond %{REQUEST_URI}!^([^.]+)\.php [NC]
RewriteRule ^(.*) blog.php?username=$1 [L]
RewriteCond %{REQUEST_URI}!^blog\.php [NC]
RewriteRule ^(.*) [mydomain.com...] [L]
Assuming if I load the file support.php, the first condition would not hold. The second condition would hold, and it would load [mydomain.com...]
This new file [mydomain.com...] is also in public_html. Wouldn't it load the .htaccess and again load [mydomain.com...] such that we have an infinite loop?
Also I would like to ask
RewriteRule ^/([^/]+)(/?) [mydomain.com...]
If the requested URI is blog.php/ (with the trailing '/'), would $1 = /blog.php or $1 = /blog.php/ ?
Thanks in advance
You won't reload the .htaccess file unless an external redirect is used, or if a subsequent internal lookup subrequest is performed. Sometimes this happens in scripted environments; See the [NS] flag if needed.
Another technique is to take steps in mod_rewrite such that the "output" of a rewrite will never match the required "input" if the rules are re-invoked. This can be accomplished using pseudo-directories and filenames if there's no better way. So, for example, you could exclude support.php in addition to blog.php:
RewriteCond %{REQUEST_URI} !^blog\.php [NC]
RewriteCond %{REQUEST_URI} !^support.php
RewriteRule ^(.*) http://www.mydomain.com/$1 [L]
> If the requested URI is blog.php/ (with the trailing '/'), would $1 = /blog.php or $1 = /blog.php/?
$1 would not have a slash, because the slash, if present in the requested URL, would go into backreference $2. The $n parameters refer to the parenthesized groups. Where nested parentheses are used, count left parentheses to determine what the n in $n will be.
In this rewrite, there is no need to enclose the "/?" in parentheses, since $2 is never referenced.
Jim
In RewriteCond %{REQUEST_URI} a request for [mydomain.com...] would be /blog.php
While in RewriteRule ^(.*)
$1 would be blog.php ? (without the preceding '/')
If true, why is it so?
2) I don't know - It is aggravating. Basically, it's because the REQUEST_URI is the entire requested URL, less the domain name, and the pattern in RewriteRule specifies the local path. By the time you get to the per-directory .htaccess RewriteRule you are in the top-level directory "/" so it is no longer part of the local path. All that sounds erudite and professorial and all, but I still screw it up all the time... :)
Jim