我使用以下规则进行网址重写。它可以正常工作到第二个参数。但是当我使用第三个参数时,它不起作用。例如,我使用http://example.com/1/2/3但它不起作用,但使用http://example.com/1/2它正在运行。
RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(\w+)$ ./index.php?api=$1
RewriteRule ^([^.]+)/([0-9]+)$ index.php?api=$1&id=$2
RewriteRule ^([^.]+)/([0-9]+)/([a-zA-Z0-9]+)$ index.php?api=$1&id=$2&action=$3
答案 0 :(得分:1)
这解决了我的问题。
RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(\w+)$ ./index.php?api=$1
RewriteRule ^(\w+)/(\w+)$ index.php?api=$1&id=$2
RewriteRule ^(\w+)/(\w+)/(\w+)$ index.php?api=$1&id=$2&action=$3
RewriteRule ^(\w+)/(\w+)/(\w+)/(\w+)$ index.php?api=$1&id=$2&action=$3&k=$4
RewriteRule ^(\w+)/(\w+)/(\w+)/(\w+)/(.*)$ index.php?api=$1&id=$2&action=$3&k=$4&v=$5
答案 1 :(得分:0)
试试这个,它对我有用。
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(\w+)$ ./index.php?api=$1
RewriteRule ^(\w+)/([0-9]+)$ index.php?api=$1&id=$2
RewriteRule ^(\w+)/([0-9]+)/([a-zA-Z0-9]+)$ index.php?api=$1&id=$2&action=$3