Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/apache/9.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php htaccess重写规则不起作用_Php_Apache_.htaccess_Mod Rewrite - Fatal编程技术网

Php htaccess重写规则不起作用

Php 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

我正在尝试重写以下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]+))?/?$ 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]