Php $\在这种特殊情况下,您将无法工作

Php $\在这种特殊情况下,您将无法工作,php,.htaccess,get,Php,.htaccess,Get,我正在尝试使用 http://www.example.com/news/id/21/title/top-10-things/?page=1用于发送页面参数,但在php中不起作用 下面是我在.htaccess文件中的设置 Options +FollowSymLinks RewriteEngine on RewriteRule ^news/(.*)/(.*)/(.*)/(.*)/$ /news.php?$1=$2&$3=$4 RewriteRule ^news/(.*)/(.*)/$ /ne

我正在尝试使用
http://www.example.com/news/id/21/title/top-10-things/?page=
1用于发送页面参数,但在php中不起作用

下面是我在.htaccess文件中的设置

Options +FollowSymLinks
RewriteEngine on
RewriteRule ^news/(.*)/(.*)/(.*)/(.*)/$ /news.php?$1=$2&$3=$4
RewriteRule ^news/(.*)/(.*)/$ /news.php?$1=$2
RewriteRule ^news/$ /news.php

尝试将
%{QUERY\u STRING}
附加到htaccess中的URL

Options +FollowSymLinks
RewriteEngine on
RewriteRule ^news/(.*)/(.*)/(.*)/(.*)/$ /news.php?$1=$2&$3=$4&%{QUERY_STRING}
RewriteRule ^news/(.*)/(.*)/$ /news.php?$1=$2&%{QUERY_STRING}
RewriteRule ^news/$ /news.php&%{QUERY_STRING}
正如Daniel所指出的,您也可以使用mod_rewrite
qsappend
QSA
标志来实现此目的。参考:

设置以将请求的查询自动附加到替换URL中的查询:

RewriteRule ^news/(.*)/(.*)/(.*)/(.*)/$ /news.php?$1=$2&$3=$4 [QSA]
RewriteRule ^news/(.*)/(.*)/$ /news.php?$1=$2 [QSA]
RewriteRule ^news/$ /news.php [QSA]
此外,如果可以更具体一些,就不应该使用
*
。在这种情况下,使用
[^/]+
可避免不必要的回溯:

RewriteRule ^news/([^/]+)/([^/]+)/([^/]+)/([^/]+)/$ /news.php?$1=$2&$3=$4 [QSA]
RewriteRule ^news/([^/]+)/([^/]+)/$ /news.php?$1=$2 [QSA]
RewriteRule ^news/$ /news.php [QSA]

对于任意数量或参数的一般解决方案,请参见。

到底什么不起作用<代码>页面不包含在
$\u GET
或什么中?您可以改用[QSA](查询字符串附加)标志。
RewriteRule ^news/([^/]+)/([^/]+)/([^/]+)/([^/]+)/$ /news.php?$1=$2&$3=$4 [QSA]
RewriteRule ^news/([^/]+)/([^/]+)/$ /news.php?$1=$2 [QSA]
RewriteRule ^news/$ /news.php [QSA]