【问题标题】:.htaccess redirect to page with anchor link.htaccess 重定向到带有锚链接的页面
【发布时间】:2022-01-27 10:32:20
【问题描述】:

我正在尝试设置一个 .htaccess 文件来将页面从一个域重定向到另一个域。在 99% 的情况下有效,不工作的 RewriteRules 如下所示 - 如果出站 URL 有 #anchor 标记,则 # 符号在浏览器中转换为字符 %23,然后页面不加载在锚点。关于如何正确解释 # 标签的任何想法?

AddType x-mapp-php5 .php
AddHandler x-mapp-php5 .php
Options -MultiViews
Options +FollowSymlinks
RewriteEngine on
RewriteRule bg/row_b1_i_pn1.php http://example.org/s-b-g/b-1#illustration-110

如果我直接将“http://example.org/s-b-g/b-1#illustration-110”剪切并粘贴到我的浏览器中,它会正常加载,但是使用 RewriteRule,加载的 URL 是“http://example.org/s-b-g/b-1%23illustration-110”......新站点是一个 drupal 站点,如果这对任何人都有帮助。谢谢。

【问题讨论】:

    标签: mod-rewrite


    【解决方案1】:

    试试NE flag:

    RewriteRule bg/row_b1_i_pn1.php http://example.org/s-b-g/b-1#illustration-110 [NE]
    

    【讨论】:

      【解决方案2】:

      因为 .htaccess 通常将 # 解释为注释,所以它有点违背正确的解释.. 因此,不要在重写规则中使用 # 而是实际使用 %23 代码。 所以你的重写变成: RewriteRule bg/row_b1_i_pn1.php http://example.org/s-b-g/b-1%23illustration-110 [NE]

      更准确地说是: 重写规则 bg/row_b1_i_pn1.php http://example.org/s-b-g/b-1/%23illustration-110 [NE]

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 2013-12-28
        • 2012-02-13
        • 1970-01-01
        • 1970-01-01
        • 2023-02-10
        • 2019-11-06
        相关资源
        最近更新 更多