WordPress修改 固定链接 形式:.htaccess 301重定向
日期和文章名改为月份(或年)和文章名
/%year%/%monthnum%/%day%/%postname% 对应的例子 /2011/11/01/htaccess301
/%year%/%monthnum%/%postname% 对应的例子 /2011/11/htaccess301
/%year%/%postname% 对应的例子 /2011/htaccess301
# 修改 year/month/day 固定链接 为 只有 year
RedirectMatch 301 ^/([0-9]+)/([0-9]+)/([0-9]+)/(.*)$ /$1/$4
# 修改 year/month/day 固定链接为 year/month
RedirectMatch 301 ^/([0-9]+)/([0-9]+)/([0-9]+)/(.*)$ /$1/$2/$4
注意:链接结尾有“/”的,相应的要在“$”前面加“/”(是 $,不是 $1 或者 $2 等),亦即:RedirectMatch 301 ^/([0-9]+)/([0-9]+)/([0-9]+)/(.*)/$ /$1/$4,以下的修改都是一样的。
%post_id% 或 %postname% 前添加 %category%
/%post_id% 修改为 /%category%/%post_id%,或者 /%category%/%post_id%.html
RedirectMatch 301 ^/(\d+)$ /(.+)/$1
RedirectMatch 301 ^/(\d+)$ /(.+)/$1.html
有“/”结尾的要注意下是 ^/(\d+)/$,记得在“$”前加“/”,其实上面已经讲了,这里再强调。
带 /archives/ 修改为其他
1. /archives/%post_id% 修改为 /%category%/%post_id% 或者 /%category%/%postname%
RedirectMatch 301 ^/archives/(\d+)$ /(.+)/$1
或者
RedirectMatch 301 ^/archives/(\d+)$ /(.+)/(.+)
2. /archives/%postname% 修改为 /%category%/%post_id% 或者 /%category%/%postname%
RedirectMatch 301 ^/archives/(.+)$ /(.+)/(\d+)
或者
RedirectMatch 301 ^/archives/(.+)$ /(.+)/$1
正则表达式:
(.+) 对应的是任意字符(包括汉字、英文字母等)
(\d+)对应的是任意数字(仅仅是阿拉伯数字)
$1 $2 $3 是前面出现过的变量的再次引用。