简体   繁体   English

重写规则WordPress的自定义URL

[英]rewrite rule wordpress custom url

I had an old website programmed for me and now i have migrated it to wordpress, but many websites still have links to the old urls and i want to redirect them to Wordpress because there are having a 404 response. 我有一个为我编程的旧网站,现在我已将其迁移到wordpress,但是许多网站仍然具有指向旧url的链接,并且由于存在404响应,我想将其重定向到Wordpress。

the old structure was: http://www.website.com/news/2013/june/01/slug-slug-slug-slug the new in wordpress: http://www.website.com/news/2013/06/01/slug-slug-slug 旧的结构是: http : //www.website.com/news/2013/june/01/slug-slug-slug-slug WordPress中的新结构: http : //www.website.com/news/2013/06 / 01 /塞段塞段塞

Note that i only need to change: 请注意,我只需要更改:

january -> 01
february -> 02
march -> 03
april -> 04
may -> 05
june -> 06
july -> 07
august ->08
september -> 09
october -> 10
november -> 11
december -> 12

Do i have to include something in wordpress' .htaccess or in the rewrite.php file? 我是否必须在wordpress的.htaccess文件或rewrite.php文件中包含某些内容? I heve been thinking that i only need to change the %monthday% variable from numeric to string... but if i update wordpress i probably need to change it again. 我一直在想,我只需要将%monthday%变量从数字更改为字符串...但是,如果我更新wordpress,则可能需要再次更改它。

If you want to use mod_rewrite, you can do this with 12 rules. 如果要使用mod_rewrite,则可以使用12条规则进行。 I am not familiar with wordpress itself and I don't know if there is an 'easy' way via the config of Wordpress itself. 我对Wordpress本身不熟悉,我也不知道通过Wordpress本身的配置是否有“简便”的方法。 Add the following rules above the rule that sends all requests to Wordpress' index.php file: 在将所有请求发送到Wordpress的index.php文件的规则上方添加以下规则:

RewriteRule ^news/([^/]+)/january/([^/]+)/(.*)$ /news/$1/01/$2/$3 [R,L]
RewriteRule ^news/([^/]+)/february/([^/]+)/(.*)$ /news/$1/02/$2/$3 [R,L]
RewriteRule ^news/([^/]+)/march/([^/]+)/(.*)$ /news/$1/03/$2/$3 [R,L]
#etc...

As always, see the documentation for information about the syntax being used. 与往常一样,请参阅文档以获取有关所使用语法的信息。

There will be 12 rules like this so you can have something like this: 将有12条这样的规则,因此您可以有以下内容:

RewriteRule ^(news/[^/]+)/january/([^/]+/.+)$ $1/01/$2 [L,R=301,NC]
RewriteRule ^(news/[^/]+)/february/([^/]+/.+)$ $1/02/$2 [L,R=301,NC]
RewriteRule ^(news/[^/]+)/march/([^/]+/.+)$ $1/03/$2 [L,R=301,NC]
RewriteRule ^(news/[^/]+)/april/([^/]+/.+)$ $1/04/$2 [L,R=301,NC]
RewriteRule ^(news/[^/]+)/may/([^/]+/.+)$ $1/05/$2 [L,R=301,NC]
RewriteRule ^(news/[^/]+)/june/([^/]+/.+)$ $1/06/$2 [L,R=301,NC]
RewriteRule ^(news/[^/]+)/july/([^/]+/.+)$ $1/07/$2 [L,R=301,NC]
RewriteRule ^(news/[^/]+)/august/([^/]+/.+)$ $1/08/$2 [L,R=301,NC]
RewriteRule ^(news/[^/]+)/september/([^/]+/.+)$ $1/09/$2 [L,R=301,NC]
RewriteRule ^(news/[^/]+)/october/([^/]+/.+)$ $1/10/$2 [L,R=301,NC]
RewriteRule ^(news/[^/]+)/november/([^/]+/.+)$ $1/11/$2 [L,R=301,NC]
RewriteRule ^(news/[^/]+)/december/([^/]+/.+)$ $1/12/$2 [L,R=301,NC]

Also make sure to have these rules on top, before any other rewrite rules. 另外,在执行其他任何重写规则之前,请确保将这些规则放在首位。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM