gpt4 book ai didi

Apache .htaccess : Redirect to an URL containing a hashtag

转载 作者:行者123 更新时间:2023-12-04 12:25:56 25 4
gpt4 key购买 nike

网址

https://example.com/moved/

https://www.example.com/moved/



应该重定向到 URL

https://my.example.com/#views/settings.php?id=2



通过 .htaccess .

这是我尝试过的:
RewriteCond %{HTTP_HOST} ^example.com
RewriteCond %{REQUEST_URI} moved$
RewriteRule (.*)$ https://my.example.com/#views/settings.php?id=2 [R=301,L]

然而,它似乎不起作用。我想原因是我想重定向到的 URL 中的 #hashtag(它标记了 .htaccess 中的注释)。

如何正确重定向?

最佳答案

将您的规则更改为:

RewriteEngine On

RewriteCond %{HTTP_HOST} ^(?:www\.)?example\.com$ [NC]
RewriteRule ^moved/?$ https://my.example.com/#views/settings.php?id=2 [R=301,L,NE,NC]
  • ^(?:www\.)?example\.com$将匹配 www.example.comexample.com
  • NE用于 无逃避#在重定向的 URL 中
  • 图案 moved/?$匹配 /moved//moved ,从而使尾部斜杠可选。

  • 确保清除浏览器缓存或使用新浏览器进行测试。

    关于Apache .htaccess : Redirect to an URL containing a hashtag,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48547302/

    25 4 0
    Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
    广告合作:1813099741@qq.com 6ren.com