RewriteRule does not work with a plus symbol (+ or *)

RewriteRule ^([az]).php$ /index.php?zig=$1 [NC,L] # working 

This rule works correctly. But

 RewriteRule ^([az]+).php$ /index.php?zig=$1 [NC,L] # not working 

or

 RewriteRule ^([az]\+).php$ /index.php?zig=$1 [NC,L] # not working 

Does not work. The difference ( + ). How to use + in the code above?

+6
source share
1 answer

This rule is in order:

 RewriteRule ^([az]+)\.php$ /index.php?zig=$1 [NC,L] 

but will create an infinite loop, since the rewritten URI /index.php also matches the regex pattern. To prevent this, you need a couple of changes, such as preventing files / directories from being overwritten and deleting the period, as this is a special regular expression metacharacter:

 # 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 ^([az]+)\.php$ index.php?zig=$1 [QSA,NC,L] 
Flag

QSA (Query String Append) saves existing query parameters when adding a new one.

+3
source

Source: https://habr.com/ru/post/987375/


All Articles