mod_rewrite保持锚链接

我想使用mod_rewrite指令将example.com/site/?page=about#whoamiredirect到example.com/site/?page=about#whoami ,但我不知道如何做到这一点

注意:锚字符#可以被传递,但是它对替换URL没有影响,除非重定向是存在锚的页面。 尽管Apache无法将窗口滚动到锚点,但浏览器会在这种情况下执行此操作。 以下是一些关于重定向锚点的Apache信息

你可以尝试这样的事情:

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

地图

http://example.com/site/anything

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

字符串site被假定是固定的。

anything字符串anything可以包含一个锚点#并且它将被传递到替换URL中。