我正在尝试重写以下网址
http://localhost/foldername/index.php?url=writeboard/index&step=1&id=1
到
http://localhost/foldername/writeboard/index/step/1/id/1
代码是
RewriteRule ^(.+?)(?:/(step)/([0-9]+))?/?$ index.php?url=$1&$2=$3 [NC,L,QSA]
我试过
RewriteRule ^(.+?)(?:/(step)/([0-9]+))(?:/(id)/([0-9]+))?/?$ index.php?url=$1&$2=$3&$4=$5 [NC,L,QSA]
它有效,但当网址变为http://localhost/foldername/writeboard/index
时,我就会得到404。
答案 0 :(得分:1)
此规则应该有效:
RewriteRule ^(.+?)/(step)/([0-9]+)/(id)/([0-9]+)/?$ index.php?url=$1&$2=$3&$4=$5 [NC,L,QSA]
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(.+?)/?$ index.php?url=$1 [NC,L,QSA]
答案 1 :(得分:0)
您还应该将RewriteBase /foldername/
添加到.htaccess文件中,因为您不在顶层。
有关RewriteBase的更多信息,请访问here。