Answer the question
In order to leave comments, you need to log in
How to write CNC rules for a self-written site?
Tell me, I want all links of the form:
site.ru/profile/
site.ru/users/
...
site.ru/любойтекст/
и т.д.
site.ru/user/1/
Options +FollowSymLinks
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)/$ index.php?module=$1 [L,QSA]
RewriteRule ^user/(\d+)*/$ index.php?module=user&id=$1 [L,QSA]
Answer the question
In order to leave comments, you need to log in
Don't reinvent the wheel, use ready-made libs: https://packagist.org/?query=router
Just swap the rules and ^user/(\d+)
put first.
Options +FollowSymLinks
RewriteEngine On
RewriteRule ^user/(\d+)/$ index.php?module=user&id=$1 [L,QSA]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)/$ index.php?module=$1 [L,QSA]
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question