Changing WordPress blog URL structure

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

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

huangapple
  • 本文由 发表于 2023年5月10日 17:45:27
  • 转载请务必保留本文链接:https://go.coder-hub.com/76216981.html
匿名

发表评论

匿名网友

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

确定