[英]Clean url in php with two get parameters
I am working on a PHP script that uses clean URIs. 我正在研究使用干净URI的PHP脚本。
My problem is, that I have one page that first uses no get parameter, then one and at the end two. 我的问题是,我有一个页面,该页面首先不使用get参数,然后使用一个页面,最后使用两个参数。
The line in the .htaccess
file currently looks like this: .htaccess
文件中的行当前如下所示:
RewriteRule ^birthing-records/([^/]+)/?$ birthing-records.php?url=$1 [L,QSA,NC]
But if I add the second parameter like this: 但是,如果我添加第二个参数是这样的:
RewriteRule ^birthing-records/([^/]+)/([^/]+)/?$ birthing-records.php?url=$1&second=$2 [L,QSA,NC]
The script redirects me to the error page. 该脚本将我重定向到错误页面。
How do I have to set this up? 我该如何设置?
Do I need two lines in the .htaccess
for that case? 在这种情况下,
.htaccess
是否需要两行?
I would normally solve this by simply calling another page but I would like to keep the exact URIs I am using right now because all of those pages are indexed at Google. 我通常可以通过简单地调用另一个页面来解决此问题,但是我想保留我现在使用的确切URI,因为所有这些页面都在Google上建立了索引。 I would really appreciate any help.
我真的很感谢您的帮助。
You need one rule for each, otherwise whenever you put one param it'll break. 每个参数都需要一个规则,否则每当放置一个参数时,它就会中断。
RewriteRule ^birthing-records/([^/]+)/?$ birthing-records.php?url=$1 [QSA,NC]
RewriteRule ^birthing-records/([^/]+)/([^/]+)/?$ birthing-records.php?url=$1&second=$2 [L,QSA,NC]
Thanks to @Martin for this note: that the L option of the first one has been removed since the L option indicates the last rule to be run (only one rule can exist with the L option) 感谢@Martin注意:由于L选项指示最后一条要运行的规则,因此第一个选项的L选项已被删除(L选项只能存在一个规则)。
Otherwise, as far as I can tell, they each work fine individually, but if you want to accept 1 OR 2 parameters, then two rules is what you need. 否则,据我所知,它们各自都可以正常工作,但是如果您要接受1个或2个参数,则需要两个规则。
You can test htaccess stuff here: http://htaccess.mwl.be/ 您可以在此处测试htaccess的内容: http : //htaccess.mwl.be/
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.