| 6:14 pm on Mar 15, 2010 (gmt 0)|
Add the [L] flag to the end of the rule.
Adding a $ end anchor to the pattern will force three or less.
There's a potential problem when only one element is present. Will it match the first pattern or the last pattern? Will it do that on all servers, and Apache versions? Could it change after a server upgrade?
Another problem comes from the * in the
[a-z-]* pattern, and the optional slashes mid-URL. A request like
example.com/something[b]//[/b]something is perfectly valid (but highly undesirable) with your rules.
I think I would use three rules, with one, two and three fixed patterns.
Don't make the trailing slash optional. Either require it, or require that it be omitted, otherwise you're introducing yet more Duplicate Content issues.
| 7:56 pm on Mar 15, 2010 (gmt 0)|
Hey thanks for your help, I think you're right so i did this. Tell me if you see something potentially wrong
RewriteRule ^(news|info)$ index.php?section=$1
RewriteRule ^(news|info)/([a-z-]+)$ index.php?section=$1&cat_1=$2
RewriteRule ^(news|info)/([a-z-]+)/([a-z-]+)$ index.php?section=$1&cat_1=$2&cat_2=$3
RewriteRule ^(news|info)/([a-z-]+)/([a-z-]+)/([a-z-]+)$ index.php?section=$1&cat_1=$2&cat_2=$3&cat_3=$4
| 8:00 pm on Mar 15, 2010 (gmt 0)|
Add the [L] flag to the end of each rule. :)
| 8:34 pm on Mar 15, 2010 (gmt 0)|
Thank you, very helpful :)
Just curious why?... You said it will prevent continuing rewriting? But the "$" at the end of the pattern seems to work alone
| 8:40 pm on Mar 15, 2010 (gmt 0)|
The [L] flags ends processing by Mod_Rewrite there and then.
Always include it unless you know a very good reason to omit it.
| 3:19 pm on Mar 16, 2010 (gmt 0)|
The [L] flag ends mod_rewrite processing if the rule is invoked.
Since it is unlikely that you would want your server to have to test all of the following rules after matching and invoking a particular rule, this is a question of efficiency. The best way to avoid prematurely-required server upgrades is to avoid wasting CPU cycles, so the [L] flag is almost always a good idea. By the time you need code that you wouldn't want to use the [L] flag on, you'll know why you don't want to use it, as it's generally only not wanted for certain "advanced" coding techniques.