我有一个为我编程的旧网站,现在我已将其迁移到wordpress,但许多网站仍然有旧网址的链接,我想将它们重定向到Wordpress,因为有404响应。
旧结构是:http://www.website.com/news/2013/june/01/slug-slug-slug-slug wordpress中的新内容:http://www.website.com/news/2013/06/01/slug-slug-slug
请注意,我只需要更改:
january -> 01
february -> 02
march -> 03
april -> 04
may -> 05
june -> 06
july -> 07
august ->08
september -> 09
october -> 10
november -> 11
december -> 12
我必须在wordpress'.htaccess或rewrite.php文件中包含一些内容吗?我一直在想我只需要将%monthday%变量从numeric更改为string ...但如果我更新wordpress我可能需要再次更改它。
答案 0 :(得分:1)
如果要使用mod_rewrite,可以使用12条规则执行此操作。我不熟悉wordpress本身,我不知道通过Wordpress本身的配置是否有一种“简单”的方式。在将所有请求发送到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...
与往常一样,请参阅the documentation以获取有关所用语法的信息。
答案 1 :(得分:0)
这样会有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]
还要确保在任何其他重写规则之前将这些规则放在首位。