mod_rewrite keeps anchor link

◇◆丶佛笑我妖孽 提交于 2019-12-01 13:24:47

问题


I want example.com/site/about#whoami to be redirected to example.com/site/?page=about#whoami using mod_rewrite directives, but I have no idea on how to do that


回答1:


NOTE: Anchor character # may be passed, but it has no effect on the substitution URL unless the redirection is to a page where the anchor exists. Although Apache cannot do the scrolling of the window down to the anchor, the browser will do it in that case. Here is some Apache information about redirecting anchors

You may try something like this:

Options +FollowSymLinks
RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^site/(.*)/?   site?page=$1  [NC,NE,L]

Maps

http://example.com/site/anything

To

http://example.com/site/?page=anything

String site is assumed to be fixed.

String anything may contain an anchor # and it will be passed in the substitution URL.



来源:https://stackoverflow.com/questions/15033757/mod-rewrite-keeps-anchor-link

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