regex - 棘手的 htaccess 重定向使用子文件夹的通配符

标签 regex .htaccess mod-rewrite url-rewrite-module

我有一个客户请求重写以下内容,其中“任何东西”可以是任何命名目录:

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

到:

 https://clientdomain.com/final-destination

我知道我可以用以下 regex 识别“任何东西” :

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

...但是我不知道如何将其纳入工作规则

最佳答案

您可以在没有任何前瞻的情况下使用此规则:

RewriteEngine On

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

此处 [^/]+ 匹配 1 个或多个不是 / 的字符。

关于regex - 棘手的 htaccess 重定向使用子文件夹的通配符,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/72887291/

相关文章:

java - 正则表达式解析Java中的类声明行

.htaccess 仅在 safari 上导致重定向循环 - http 到 https

apache - 如何在 Apache 服务器上启用 mod_rewrite

.htaccess - 通过 .Htaccess 进行 URL 重定向在 Php Codeigniter 中不起作用

apache - RewriteBase 的值可用作变量/引用吗?

apache - 无操作 Apache mod_rewrite 规则

debugging - 除了使用浏览器之外,是否有更好的方法来测试或调试 Mod 重写规则?

regex - Notepad++ 克隆每一行

JavaScript 正则表达式(字符串应仅包含字母、空格、连字符)

Java 扫描器定界符