.htaccess redirect anchor page/page#anchor to url

半世苍凉 提交于 2019-12-02 07:25:58

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

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>

I believe the data after # is considered a fragment. Fragment data is not sent to the server. Therefore you cannot capture it using modrewrite.

the NE flag may let you capture ^/page/page and redirect to http://www.example.com/page/page#anchor but it won't work the other way around.

A simple JavaScript replace will replace the links and allow the users to click on them. But that won't help you with SEO if that is your ultimate goal.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!