htaccess的重定向锚页/页#锚网址 [英] .htaccess redirect anchor page/page#anchor to url

查看:134
本文介绍了htaccess的重定向锚页/页#锚网址的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我如何重定向页/页#锚 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>

这篇关于htaccess的重定向锚页/页#锚网址的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆