英文:
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.
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论