更改URL路径中的子目录,保持其余部分不变的最简单方法是什么?

huangapple go评论130阅读模式
英文:

What is the easiest way to change a sub directory in the path of a URL, and leave the rest the same?

问题

我们有一个WordPress网站,最近更改了事件的slug,并且现在使用了新的路径。

例如,单个事件之前是在 https://website.com/event/title,现在在 https://website.com/learn/title

我需要确保所有旧URL的链接实例都重定向到新的URL。对此,最佳方法是什么?

我认为我可以在htaccess文件中使用一些重写规则之类的东西,但我不太确定。

英文:

We have a WordPress site that we recently changed the slug for the events and are now using a new path.

For example, the individual events were at https://website.com/event/title , but are now at https://website.com/learn/title.

I need to make sure all link instances of the old url are redirected to the new. What would be the best method for this?

I think I could possibly use some rewrite rules in the htaccess file or something like that, but I'm not sure.

答案1

得分: 0

使用像Redirection这样的插件将使这变得非常简单。您可以使用正则表达式来实现您的需求,正则表达式看起来像这样(确保从下拉菜单中选择"Regex"):

源:^/event/(.*)$
目标:https://example.com/learn/$1

请注意,在WordPress识别到404后执行重定向比通过.htaccess创建重定向性能更好。此外,一些网络托管提供了一个重定向层,提供了最高的性能。

英文:

Using a plugin like Redirection will make this pretty trivial. A regular expression for your use would look something like this (make sure to select "Regex" from the dropdown):

Source: ^/event/(.*)$
Target: https://example.com/learn/$1

Note that performing redirects after WP identifies a 404 is more performant than creating redirects through .htaccess. Also some web hosts include a redirection layer that offers the highest performance.

huangapple
  • 本文由 发表于 2023年6月30日 05:12:57
  • 转载请务必保留本文链接:https://go.coder-hub.com/76584633.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定