RewriteRule ^([a-z]).php$ /index.php?zig=$1 [NC,L] # working
This rule is working correctly. But
RewriteRule ^([a-z]+).php$ /index.php?zig=$1 [NC,L] # not working
or
RewriteRule ^([a-z]\+).php$ /index.php?zig=$1 [NC,L] # not working
Is not working. Difference is (+
). How to use +
in the code above?
This rule is fine:
RewriteRule ^([a-z]+)\.php$ /index.php?zig=$1 [NC,L]
but will create an infinite loop since rewritten URI /index.php
also matches the regex pattern. To prevent this you need couple of changes like preventing files/directories from this rewrite and escape the dot as it is a special regex meta character:
# If the request is not for a valid directory
RewriteCond %{REQUEST_FILENAME} !-d
# If the request is not for a valid file
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^([a-z]+)\.php$ index.php?zig=$1 [QSA,NC,L]
QSA
(Query String Append) flag preserves existing query parameters while adding a new one.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With