繁体   English   中英

.htaccess URL重写2个变量

[英].htaccess URL rewrite for 2 variables

我在使用.htaccess重写URL时遇到问题,当URL看起来像原始网址时: http//www.example.com/page.php?id = 1& name = test重写后: http:/ /www.example.com/page-1-test它工作正常

但经理要求连字符而不是空格,所以我这样做了

$name = str_replace(" ", "-", $name);

然后我回显$ page_name http://www.example.com/page.php?id=2&name=test-some-other-text

所以看起来像http://www.example.com/page-2-test-some-other-text

当我尝试$ _GET ['id']时,它需要2-test-some-other-text作为id;

这是我在.htaccess中的重写规则

RewriteRule page-(.*)-(.*)$ page.php?id=$1&name=$2

由于ID是一个数字,请尝试以下规则:

RewriteRule page-([0-9]+)-(.*)$ page.php?id=$1&name=$2

它只匹配ID的数字,然后在最后一个破折号结束,而不是继续尝试贪婪的匹配。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM