Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/haskell/8.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 为什么我的mod rewrite不能在我的分页上工作_Php_Mod Rewrite - Fatal编程技术网

Php 为什么我的mod rewrite不能在我的分页上工作

Php 为什么我的mod rewrite不能在我的分页上工作,php,mod-rewrite,Php,Mod Rewrite,可能重复: 我已经编写了一个.htaccess文件,它将下面的行正确地转换为 http://localhost/questions/32/new-question-from-peter 进入 我使用的代码是 RewriteRule ^questions/([0-9]+)/[^/]*(?:\?(.+)=(.*))?$ public/questions.php?question_id=$1&$2=$3 [NC,L] 但是,当url为以下内容时 http://localhost/qu

可能重复:

我已经编写了一个.htaccess文件,它将下面的行正确地转换为

http://localhost/questions/32/new-question-from-peter
进入



我使用的代码是

RewriteRule ^questions/([0-9]+)/[^/]*(?:\?(.+)=(.*))?$ public/questions.php?question_id=$1&$2=$3 [NC,L]

但是,当url为以下内容时

http://localhost/questions/32/new-question-from-peter?page= <int>
它工作得很好


有人能帮我一下吗,我的代码哪里出了问题

调试mod_rewrite的一个好的、通用的方法是设置一个日志文件,并检查在重写过程中发生了什么:

<IfModule mod_rewrite.c>
RewriteLog "/var/log/rewrite.log"
RewriteLogLevel 3
</IfModule>

重写日志“/var/log/rewrite.log”
重写日志级别3

您应该使用
QSA
(查询字符串附加)标志,如下所示:

RewriteRule ^questions/([0-9]+)/[^/]*/?$ public/questions.php?question_id=$1 [NC,L,QSA]

在这种情况下,查询字符串(
&page=2
)是自动处理的,因此您不需要在正则表达式中处理它,并将其附加到重写的URL的末尾。

非常感谢,为我节省了大量时间没有问题。别忘了接受对你最有帮助的答案。如果可以的话:-)我也喜欢被接受!
<IfModule mod_rewrite.c>
RewriteLog "/var/log/rewrite.log"
RewriteLogLevel 3
</IfModule>
RewriteRule ^questions/([0-9]+)/[^/]*/?$ public/questions.php?question_id=$1 [NC,L,QSA]