.htaccess重定向网址并从结果网址中删除#591

时间:2017-02-13 13:47:37

标签: apache .htaccess redirect

我的网站反向链接为

http://localhost/babycare/article/detail/93#591

我想将其重定向到一个新的用户友好的网址,如

http://localhost/babycare/article/detail/feeding_aversion

我在.htaccess文件中编写的代码在这里

RewriteCond %{THE_REQUEST} /article/detail/93 [NC] 
RewriteRule ^/?(babycare)? /article/detail/Feeding_Aversion? [R=301]

但它重定向到

http://localhost/babycare/article/detail/feeding_aversion#591

我如何从网址中删除#591。

1 个答案:

答案 0 :(得分:1)

您遇到的问题是位置哈希通常只存在于浏览器中,并不意味着服务器要处理。

在以下答案中更详细地介绍了它;

URL Fragment and 302 redirects

Which one is better pushstate or location.hash?

如果问题出现在很多问题上,您可以使用Javascript删除哈希值。

location.hash = "";

应该实现您正在寻找的东西 - 显然它需要进入每一页。

相关问题