使用通配符的棘手的HTACCESS重定向

发布于 2025-02-13 08:20:59 字数 440 浏览 0 评论 0原文

我有一个客户请求重写以下内容,其中“任何事物”可以是任何名称的目录:

https://clientdomain.com/anything/final-destination

to:

 https://clientdomain.com/final-destination

我知道我可以识别以下正则

(?<=clientdomain.com\/)(.*)(?=final-destination)

...但是如何将其纳入工作规则使我难以置信

I have a client request to rewrite the following, where "anything" can be any named directory:

https://clientdomain.com/anything/final-destination

to:

 https://clientdomain.com/final-destination

I know I can identify "anything" with the following regex:

(?<=clientdomain.com\/)(.*)(?=final-destination)

...but how to incorporate that into a working rule eludes me

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

痴意少年 2025-02-20 08:20:59

您可以使用此规则,而无需任何lookahead:

RewriteEngine On

RewriteRule ^[^/]+/(final-destination/?)$ /$1 [L,NC,R=301]

shere [^/]+匹配的1个或更多不是/的字符中的1个或更多字符。

You may use this rule without any lookahead:

RewriteEngine On

RewriteRule ^[^/]+/(final-destination/?)$ /$1 [L,NC,R=301]

Here [^/]+ matches 1 or more of any character that is not /.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文