英文:
Changing WordPress blog URL structure
问题
你可以尝试使用.htaccess 文件来进行重定向,可能需要使用通配符来处理这种情况。
英文:
I have blog with structure
example.com/old-url/post-name
I want change old URL with a new URL like
example.com/new-url/post-name
I can change the structure from WordPress but needs a redirect to keep the posts working. There are 1000+ blog posts.
I think .htaccess is the way to go. A wildcard redirect? Or any other approach?
答案1
得分: 2
尝试使用以下内容:
RewriteEngine On
RewriteBase /
RewriteRule ^old-url/(.*)$ /new-url/$1 [R=302,L]
这将会把包含 old-url
的任何URL重定向到对应的 new-url
。包括任何子目录。
在上述代码中,我设置了 302
标志,这使它成为一个临时重定向。一旦您确定它按预期工作,然后将其更改为 301
,这是一个永久重定向。
因此,例如:
example.com/old-url/post-name
将会变成 example.com/new-url/post-name
。
英文:
Try using the following:
RewriteEngine On
RewriteBase /
RewriteRule ^old-url/(.*)$ /new-url/$1 [R=302,L]
This should take any URL that includes old-url
and turn them into new-url
. Including any sub-directories.
In the above I've set the 302
flag, this makes it a temporary redirect, once you know this is working as you expected then change it to 301
which is a permanent redirect.
So for example:
example.com/old-url/post-name
will become example.com/new-url/post-name
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论