Reputation: 191
I'm getting trouble with capture groups in a rewrite rule. Here is a sample:
RewriteRule ^([a-z]+)\.php$ test.php?captureGroup=$1
The capture group I'm getting is "test" instead of what I typed in the address bar. Strangely this works fine:
RewriteRule ^([0-9]+)\.php$ test.php?captureGroup=$1
i.e a url like "88.php" gives me "88" as capture group. What could be the problem?
Upvotes: 1
Views: 66
Reputation: 786291
It is because your target URI (test.php
) is also matching [a-z]+.php
pattern and rule is executing twice.
You can use this to prevent that:
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^([a-z00-9]+)\.php$ test.php?captureGroup=$1
Upvotes: 2