Forum Moderators: phranque
# I never want anything to match example.com/includes, etc
RewriteCond %{REQUEST_URI} ^/(includes|images|cgi-bin)/
RewriteRule ^ - [L]
RewriteRule ^(includes|images|cgi-bin)/ - [L]
listing the three directories in order of frequency of access if there's a significant difference among the three. RewriteCond %{REQUEST_URI} !^/example/(foo|bar) [NC]
RewriteRule ^example/([a-z-]+)/?([a-z-]+)?/?$ /example/list.php?var1=$1&var2=$2 [NC,QSA,NE,L] RewriteRule ^example/(!(foo|bar))/?([a-z-]+)?/?$ /example/list.php?var1=$1&var2=$2 [NC,QSA,NE,L] RewriteRule ^example/(?!foo|bar)/?([a-z-]+)?/?$ /example/list.php?var1=$1&var2=$2 [NC,QSA,NE,L] RewriteRule ^example/(?!foo|bar)/?([a-z-]+)?/?$ /example/list.php?var1=$1&var2=$2 [NC,QSA,NE,L]That's because, in the rule as written, there is no $2. A lookahead (or lookbehind) doesn’t capture. At this point it's probably a little less confusing if you start by writing the rule without thinking of the exceptions, and then once you've got the rule formulated properly--right now it’s got altogether too many ? for my taste--you can then reinsert the (?!foo|bar) lookahead if desired.
This captures $1 the way I'm expecting, but not $2. So this:
But in the OP it looked like a flat-out [L], target - (nothing), take-no-more-action.
That's because, in the rule as written, there is no $2. A lookahead (or lookbehind) doesn’t capture.
RewriteRule ^example/(?!foo|bar)/?([a-z-]+)?/? /example/list.php?cat=$1&subcat=$3 [NC,QSA,NE,L] Will this rule ultimately, when everything is sorted out, be in htaccess or config? It may make a difference in speed and efficiency, since Regular Expressions in htaccess have to be compiled over again on every single request, while in config the server learns them and remembers them.
This isn't the same tester that thinks mod_rewrite behaves like mod_alias, is it?
The obvious cause is that the pattern in the rule does not have a $ closing anchor, making it match all requests all the time.
Incidentally, why is it
([a-z-]+)?
rather than
([a-z-]*)
? Seems like they would be identical, at a savings of one byte ;)
do you know a better tester?Well, yes: Your own site. There’s no substitute for trying things out on your own server, with your own configuration, your own filenames. I maintain a test site for just this reason: for the cost of a domain-name registration, I can experiment fully and at length, with no risk of harming any “real” site.
...and (b) why $3 instead of $2?
Well, yes: Your own site. There’s no substitute for trying things out on your own server, with your own configuration, your own filenames. I maintain a test site for just this reason: for the cost of a domain-name registration, I can experiment fully and at length, with no risk of harming any “real” site.
For whatever reason, my browser had cached the R=301Yes, browsers cache permanent redirects. They’re supposed to. That’s why experiments should be done with a temporary redirect (R=302, R alone, or no flag at all).
I'm sure most of you code directly via SSHNope, not me. I do all my text editing, for all purposes--including HTML--in SubEthaEdit. htaccess files are saved locally with names like htaccess_sitename, and then get renamed .htaccess with leading dot when uploading. Locally I do have a file that is actually called .htaccess, one for each site, but that's only for use with MAMP; it doesn’t have all the content of my actual htaccess file, since it obviously doesn’t need things like access control.