我在使用 .htaccess 重写 URL 时遇到问题,当 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