$ _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/(.*)/(.*)/$ /news.php?$1=$2
RewriteRule ^news/$ /news.php
答
尝试追加%{QUERY_STRING}
的网址,在你的htaccess。
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}
正如丹尼尔提到的,你也可以使用mod_rewrite的qsappend
或QSA
标志用于这一目的。 REF:http://httpd.apache.org/docs/2.0/mod/mod_rewrite.html
Options +FollowSymLinks
RewriteEngine on
RewriteRule ^news/(.*)/(.*)/(.*)/(.*)/$ /news.php?$1=$2&$3=$4 [QSA]
RewriteRule ^news/(.*)/(.*)/$ /news.php?$1=$2 [QSA]
RewriteRule ^news/$ /news.php [QSA]
+3
您可以改为使用[QSA](查询字符串附加)标志。 – 2010-09-27 14:15:35
答
设置QSA flag获得自动追加到一个在替换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]
以及用于任意数目或参数的一般的解决方案,请参见Rewriting an arbitrary number of path segments to query parameters。
什么不工作? 'page'不包含在'$ _GET'中或者什么? – 2010-09-27 14:12:40