【问题标题】:mod_rewrite keeps anchor linkmod_rewrite 保持锚链接
【发布时间】:2013-02-08 15:16:09
【问题描述】:

我希望使用 mod_rewrite 指令将 example.com/site/about#whoami 重定向到 example.com/site/?page=about#whoami,但我不知道该怎么做

【问题讨论】:

    标签: apache mod-rewrite anchor


    【解决方案1】:

    注意:可以传递锚字符 #,但它对替换 URL 没有影响,除非重定向到存在锚的页面。尽管 Apache 不能将窗口向下滚动到锚点,但在这种情况下浏览器会这样做。这是一些Apache information about redirecting anchors

    你可以试试这样的:

    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 可能包含一个锚点 #,它将在替换 URL 中传递。

    【讨论】:

    • 哦,谢谢,我知道了。我已经测试过,它仍然向下滚动页面到锚点:D
    猜你喜欢
    • 1970-01-01
    • 2015-05-14
    • 2014-03-20
    • 2022-01-26
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2010-12-22
    相关资源
    最近更新 更多