RewriteRule ^([\w-]+)/([a-z0-9]+)/([a-z-0-9]+)$ index.php?p=$1&bay=$2&map=$3 [L]
RewriteRule ^test/([\w-]+)/(\d+)$ index.php?page=$1&tab=$2 [L]
You basically have a "conflict" with these two rules. These rules are processed in the order in which they appear in the file. Some of your URLs, that you are expecting to be processed by the second rule, are matched and consequently processed by the first rule instead. Once the URL is processed by the first rule, the second rule is effectively bypassed.
(You should have been able to have seen this by debugging the URL parameters your script was seeing. index.php
should have still been called.)
1. example.com/test/example-1/1
This "works" because it is not matched by the first rule. The first rule does not allow hyphens in the second path segment, ie. ([a-z0-9]+)
does not match example-1
. The regex only matches 1 or more a-z (lowercase) and 0-9 characters. So, processing continues and is caught by the second rule, which matches successfully.
i need to change example2
to Example2
For the same reason as above. Example2
(with an uppercase E
) does not match the first rule (specifically, ([a-z0-9]+)
does not match Example2
). As noted above, the first rule only matches lowercase a-z (and 0-9) in the second path segment. So, processing falls through to the second rule, which matches due to the \w
shorthand character class which also includes the uppercase A-Z
letters.
In some ways (apart from the uppercase letters and hyphen in the second path segment) the first rule is more "generic" so ends up catching the URLs you are expecting to fall through to the second rule.
The more specific rule(s) should appear first. The rules should be in order of specificity. The more specific rules first; the more generic rules last.
So, in your case - for these specific URLs - you can solve the problem by simply reversing these directives.
This may be sufficient for your particular URLs. For example, if all URLs that start /test/
should be processed by the (new) first rule then all should be good. However, if there are any "special cases" that should be processed by the second rule, such as /test/123/123
then you will need to readdress these rules and/or URL structure.
Aside:
I wanted to rewrite these URLs:
1 - example.com/test/?page=example-1&tab=1
2 - example.com/test/?page=example2&tab=1
And i wanted these results bellow:
1 - example.com/test/example-1/1
2 - example.com/test/example2/1
It's really the other way round. (Although many do describe it in this way, it is confusing, as it seemingly describes the overall result you are trying to achieve, not the process?)
For example, you are rewritting example.com/test/example-1/1
to example.com/test/?page=example-1&tab=1
(not the other way round). The later is the "result".