htaccess的重定向锚页/页#锚网址重定向、网址、htaccess

2023-09-02 01:06:48 作者:抖音大全

我如何重定向页/页#锚 http://www.example.com/page/page

我尝试以下code,但它不工作

I tried the following code, but it's not working

RewriteRule ^page/page#anchor http://www.example.com/page/page [NE,L]

你能帮帮我吗?

Could you please help me?

彼得·

推荐答案

这不能以来URI组件服务器端后做的是通过客户端只处理

That can't be done on server side since URI component after # is handled by client side only.

您也可以使用这个JavaScript code做相同的:

You can alternatively use this Javascript code to do the same:

<script>
if (location.href.indexOf("#") > -1) {
   location.assign(location.href.replace(/(page/page)#anchor/i, "$1"));
}
</script>