我想更改此网址:
Site.com/Controller/myController.php?action=myAction&var1=y&var2=z
到:
Site.com/myAction/var1/y/var2/z/..../varn/valn
变量可以存在与否。
无重定向
我尝试了很多解决方案,但我所做的只是用项目替换Controller / myController.php:
RewriteEngine on
RewriteRule ^items/(.*)$ Controllers/myController.php$1
谢谢你
答案 0 :(得分:0)
您可以在DOCUMENT_ROOT/.htaccess
文件中使用此规则:
RewriteEngine On
RewriteBase /
# recursion to replace /action/n1/v1/n2/v2 to QUERY_STRING
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(\w+)(/.*)?$ Controllers/myController.php$2?action=$1 [L,QSA]
RewriteRule ^(Controllers/myController\.php)/([^/]+)/([^/]+)(/.*)?$ $1$4?$2=$3 [L,NC,QSA]