我必须传递 slug 以及其他参数来检索信息,但我想使用 .htaccess 隐藏 url 中显示的参数,但 slug



我必须传递 slug 以及其他参数来检索信息,但我想隐藏 url 中显示的参数,除了 slug。我已经尝试了很多.htaccess,但它仍然没有给我积极的结果。

实际网址是这样的http://localhost/qa1/reply.php?user_id=69%20&ans_id=44%20&id=71%20&post_url=what-is-the-best-example-of-agile-process

我想将其转换为http://localhost/qa1/reply/69/44/71/what-is-the-best-example-of-agile-process

这是我将参数传递给回复.php页面的代码。

echo "<a href='reply.php?user_id=$user_id &ans_id=$ans_id &id=$id &post_url=$post_url'>view replies</a>";

以及我在下面的.htaccess中所做的:

RewriteEngine On
RewriteRule ^reply/([0-9]+)/([0-9]+)/([0-9]+)/([0-9a-zA-Z]+) reply.php?user_id=$2&ans_id=$3&id=$4&post_url=$5 

除了空白的白屏外,什么都没有显示。

如何解决问题?

我认为

在答案中总结一下可能是有意义的。尤其是在您评论询问重定向之后。您需要将重写和重定向分开,因为它们需要在相反的方向上出现:

RewriteEngine On
RewriteCond %{QUERY_STRING} ^user_id=(d+)&ans_id=(d+)&id=(d+)&post_url=([0-9a-zA-Z]+)$ 
RewriteRule ^reply.php$ reply/%1/%2/%3/%4 [R=301,QSD]
RewriteRule ^reply/(d+)/(d+)/(d+)/([0-9a-zA-Z]+)/?$ reply.php?user_id=$2&ans_id=$3&id=$4&post_url=$5 [END]
最好从 http-302

重定向开始,只有在一切正常后才将其更改为 http-301。这样,您就可以在开发

...

相关内容

最新更新