如何使此正则重写规则适用于 /和 /没有 /?

发布于 2025-02-03 19:56:14 字数 515 浏览 4 评论 0原文

我制作了以下重定向规则,以用于WordPress的htaccess中,这似乎有效:

RewriteCond %{REQUEST_URI} /nl/my-impact/
RewriteRule ^nl/(.+)$ $1nl/ [R=301,L]

但是它应该重定向:

  • https://alivetoearth.org/nl/my-impact/my-impact/florian
  • https ://alivetoearth.org/nl/my-impact/florian/

to: https://alivetoearth.org/my-impact/florian/nl/

我如何确保在两种情况下都能工作?

现在,我可以使它在一个或另一个中起作用。如果有一种更好的方法来编写整个重定向,我也很想知道。

I made the following redirect rule to be used in htaccess for Wordpress which seems to work:

RewriteCond %{REQUEST_URI} /nl/my-impact/
RewriteRule ^nl/(.+)$ $1nl/ [R=301,L]

But it should redirect both:

  • https://alivetoearth.org/nl/my-impact/florian
  • https://alivetoearth.org/nl/my-impact/florian/

to:
https://alivetoearth.org/my-impact/florian/nl/

How can I make sure it works in both cases?

Now I can just make it work in one or the other. If there is a better way to write the entire redirect I would also love to know.

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

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

发布评论

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

评论(1

本王不退位尔等都是臣 2025-02-10 19:56:14

您可以使用此重定向规则:

RewriteRule ^(nl)/([^/]+/[^/]+)/?$ /$2/$1/ [R=301,L,NC]

You may use this redirect rule:

RewriteRule ^(nl)/([^/]+/[^/]+)/?$ /$2/$1/ [R=301,L,NC]
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文