Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
我不是正则表达式专家,我在看起来很简单的任务上失败了:
我需要像这样 301 重定向网址:
/en/example/ www.example.com/hello-world/ /en/example/ANYTHING www.example.com/foobar/
我能想到的唯一方法就是这样
/en/example/(.+) www.example.com/foobar/
但这覆盖了另一条规则,我无法在单独的 url 上重定向“/en/example/”。
为此,您需要有 2 条单独的规则。首先是具体的,然后是一般的。
RewriteRule ^en/example/?$ /hello-world/ [L,NC] RewriteRule ^en/example/(.+?)/?$ /foobar/ [L,NC]