Php htaccess重写规则不起作用
我正在尝试重写以下urlPhp htaccess重写规则不起作用,php,apache,.htaccess,mod-rewrite,Php,Apache,.htaccess,Mod Rewrite,我正在尝试重写以下url http://localhost/foldername/index.php?url=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]+))?/?$ ind
http://localhost/foldername/index.php?url=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]
但当url变为http://localhost/foldername/writeboard/index
那么我得到了404。这个规则应该有效:
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]
您还应该将
RewriteBase/foldername/
添加到.htaccess文件中,因为您不在顶层
有关RewriteBase的更多信息,请访问。谢谢Anubhava。它工作,但当我在那得到404。好的,现在看到更新的规则,但你没有提到这个要求之前。该页面的工作,但我没有得到的步骤和id的价值,现在这个url当我回显url,然后它打印writeboard/questions/step/1/id/66非常好..它是工作的。再次感谢你。我已经添加了。只是重写规则不起作用。
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]