我想更改网址的格式。假设我的页面是
example.com/add.php?mod=new
我想将其更改为
example.com/add/new
我找到了以下代码,但它只删除了网址
中的文件扩展名RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^([^\.]+)$ $1.php [NC,L]
答案 0 :(得分:1)
您需要另一条规则来处理查询参数:
RewriteEngine On
# to support /add/new
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^([\w-]+)/([\w-]+)/?$ $1.php?mod=$2 [QSA,L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME}.php -f
RewriteRule ^(.+?)/?$ $1.php [L]