无法获取URL的第二个参数在.htaccess的重写规则 [英] Unable to get the 2nd Parameters of URL in Rewrite rule of .htaccess
问题描述
我在得到有另一个问题,第二次把我的路线参数我不能在这里得到了第二个参数是规则我写的:
i am having another problem in getting 2nd Get Parameter of my Route i am unable to get the 2nd parameter here is the rule i wrote:
RewriteRule ^knowledgebase/topics/([0-9]+)-([A-Za-z0-9-]+)\?page=([0-9]+)?$ topic.php?id=$1&page=$3 [NC,L]
预期的URL是
the expected URL is
knowledgebase/topics/6457-microsoft-office-application-information?page=2
在这里 6457
是第一个获得变量则 -
则标题微软按职位应用信息
然后?页=
然后我的第二个GET参数是 2
却无力获取该网页的变量
here 6457
is the first get variable then -
then title microsoft-office-application-information
then ?page=
then my 2nd get parameter that is 2
but unable to get that page variable
这是什么问题就是什么问题的正则表达式?
what is the problem is something wrong in Regex ??
推荐答案
查询字符串不包含在重写URL模式。从 RewriteRule指令
The query string is not included in the rewrite url pattern. From RewriteRule Directive
什么是匹配的?
如果你想匹配的主机名,端口或查询字符串,使用的RewriteCond与%{HTTP_HOST}%{} SERVER_PORT或%{QUERY_STRING}分别变量。
What is matched?
If you wish to match against the hostname, port, or query string, use a RewriteCond with the %{HTTP_HOST}, %{SERVER_PORT}, or %{QUERY_STRING} variables respectively.
您必须单独提取部分
RewriteCond %{QUERY_STRING} page=([0-9]+)
RewriteRule ^knowledgebase/topics/([0-9]+)-[A-Za-z0-9-]+ topic.php?id=$1&page=%1 [NC,L]
这篇关于无法获取URL的第二个参数在.htaccess的重写规则的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!