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.