Apache rewrite 规则如下(.htaccess):

# BEGIN WordPress
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
</IfModule>

# END WordPress

ISAPI rewrite分,目前有两个版本,2.X和3.X,同时还有收费版和免费版之分,收费版与免费版存在一些功能上的区别。

以下是我找到的一个版本,很简洁,但存在问题(比如不能加载图片和CSS等资源文件),可以说没用:

文件名httpd.ini,置于网站根目录下


[ISAPI_Rewrite]
CacheClockRate 3600
RepeatLimit 32

RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^/(.*)$ /index.php

以下是我修改的一个版本(用于ISAPI rewrite 2.X,如有问题,再打补丁):
httpd.ini,置于wordpress根目录下:

[ISAPI_Rewrite]
CacheClockRate 3600
RepeatLimit 32

RewriteRule /wp-(.*) /wp-$1 [L]
RewriteRule ^/$ /index.php [L]
#下面一条是WordPress单篇文章的固定链接的rewrite规则,根据需要改动即可,
#需熟悉WordPress的index.php?后面可带的参数
RewriteRule /([0-9]{4})/(.*)/(.*)/$ /index.php?year=$1&category_name=$2&name=$3
RewriteRule /tag/(.*) /index.php?tag=$1
RewriteRule /(.*) /index.php/$1 [L]

总之,简单粗暴而有效的方式,就是根据自己博客的链接要求,一条一条的用正则表达式写rewrite规则,虽然这样做不太优雅且稍显冗长,却简单有效。

WordPress的结构标签(参数),见http://codex.wordpress.org/zh-cn:%E4%BD%BF%E7%94%A8%E5%9B%BA%E5%AE%9A%E9%93%BE%E6%8E%A5

网上找到一些比较疯狂的rewrite写法,可以适当借鉴:


RewriteRule /tag/(.*) /index.php?tag=$1
RewriteRule /(about|contact|tags|sitemap|link|) /index.php?pagename=$1
RewriteRule /category/(.*)/(feed|rdf|rss|rss2|atom)/?$ /wp-feed.php?category_name=$1&feed=$2
RewriteRule /category/?(.*) /index.php?category_name=$1
RewriteRule /author/(.*)/(feed|rdf|rss|rss2|atom)/?$ /wp-feed.php?author_name=$1&feed=$2
RewriteRule /author/?(.*) /index.php?author_name=$1
RewriteRule /rss.xml /wp-feed.php/?feed=rss2
RewriteRule /feed/?$ /wp-feed.php/?feed=rss2
RewriteRule /comments/feed/?$ /wp-feed.php/?feed=comments-rss2
RewriteRule /([0-9]+).html /index.php?p=$1 [I]
RewriteRule /page/(.*)/?s=(.*) /index.php?s=$2&paged=$1
RewriteRule /page/(.*) /index.php?paged=$1
RewriteRule /date/([0-9]{4})([0-9]{1,2})([0-9]{1,2})/([^/]+)/?([0-9]+)?/?$ /index.php?year=$1&monthnum=$2&day=$3&name=$4&page=$5
RewriteRule /date/([0-9]{4})/([0-9]{1,2})/([0-9]{1,2})/?$ /index.php?year=$1&monthnum=$2&day=$3&page=$4
RewriteRule /date/([0-9]{4})/([0-9]{1,2})/?$ /index.php?year=$1&monthnum=$2&page=$3
RewriteRule /([0-9]+).html/(feed|rdf|rss|rss2|atom) /index.php?feed=rss2&p=$1
RewriteRule /([0-9]+).html/trackback /wp-trackback.php?p=$1

发表评论

电子邮件地址不会被公开。 必填项已用*标注