gpt4 book ai didi

regex - Apache RedirectMatch 与正则表达式

转载 作者:行者123 更新时间:2023-12-01 13:29:19 26 4
gpt4 key购买 nike

我试图将每个没有 # 的 URL 重定向到相同的,但在 /path/ 之后带有 #

例子:

此网址:https://www.example.com/path/test/test

需要重定向到这个 url:https://www.example.com/path/#/test/test

所以我写了这个重定向匹配:

RedirectMatch permanent ^/path/(?!#)(.*)$ /path/#/$2

但它不起作用。

浏览器向我显示此消息:ERR_TOO_MANY_REDIRECTS

最佳答案

你可以只在你的站点根目录中使用这个规则.htaccess:

RewriteEngine On

RewriteRule ^/?(path)/(.+)$ /$1/#/$2 [L,NE,NC,R=301]

它将重定向 /path/test/test/path/#test/test

不需要检查 RewriteRule 中是否存在 #,因为客户端浏览器不会将 # 之后的任何部分发送到 Web 服务器无论如何。

关于regex - Apache RedirectMatch 与正则表达式,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46836342/

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