WordPress自定义URL的Rewrite规则
在PrugeHosting上申请的一个免费主机空间上做了一个Wordpress , 设置 自定义链接结构之后居然发现所有的链接都失效,实现不了伪静态,本以为是主机空间不支持 mod_rewrite,昨天问 客服他们说支持,我就开始考虑是不是.htaccess 文件的问题,到wordpress根目录,发现没有这个文件,居然没有生成?我就自己建了一个,并且文件将属以及wordpress目录性更改为777,重新设置永久链接还是不出现,这就怪了,莫非要我手写不成?没办法,硬着头在.htaccess中写了如下规则:
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(about|contact|links|archive)$ index.php?pagename=$1
RewriteRule ^page/([0-9]{1,10}) index/.php/?page=$1
RewriteRule ^search/([^/]+) index.php?s=$1&page=$2
RewriteRule ^search/([^/]+)/page/([0-9]{1,3}) index.php?s=$1
RewriteRule ^tag/([^/]+) index.php?tag=$1
RewriteRule ^tag/([^/]+)/page/([0-9]{1,3}) index.php?tag=$1&page=$2
RewriteRule ^category/([^/]+) index.php?category_name=$1
RewriteRule ^category/([^/]+)/page/([0-9]{1,3}) index.php?category_name=$1&page=$2
RewriteRule ^author/([^/]+) index.php?author_name=$1
RewriteRule ^author/([^/]+)/page/([0-9]{1,3}) index.php?author_name=$1&page=$2
# 我将永久链接设置为: /%year%/%monthnum%/%postname%/.html
RewriteRule ^([0-9]{4})/([0-9]{1,2})/([^/]+)/.html$ index.php?year=$1&monthnum=$2&name=$3
RewriteRule ^([0-9]{4})/([0-9]{1,2}) index.php?year=$1&monthnum=$2&page=$3
RewriteRule ^([0-9]{4})/([0-9]{1,2})/page/([0-9]{1,3}) index.php?year=$1&monthnum=$2&page=$3
RewriteRule ^category/(.*)/(feed|rdf|rss|rss2|atom)/?$ wp-feed.php?category_name=$1&feed=$2
RewriteRule ^author/(.*)/(feed|rdf|rss|rss2|atom)/?$ wp-feed.php?author_name=$1&feed=$2
RewriteRule ^rss.xml wp-feed.php/?feed=rss2
RewriteRule ^feed/?$ wp-feed.php/?feed=rss2
RewriteRule ^comments/feed/?$ wp-feed.php/?feed=comments-rss2
IndexIgnore .htaccess */.??* *~ *# */HEADER* */README* */_vti*
期间经过了N次的测试于修改,终于测试没有问题。本来应该是Wordpress应该生成的东西,居然还要自己手写,很不爽。
同样,在Discuz中,实现伪静态,需要在Discuz的目录下的.htacces加入这样的规则:
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^archiver/([a-z0-9/-]+/.html)$ archiver/index.php?$1
RewriteRule ^forum-([0-9]+)-([0-9]+)/.html$ forumdisplay.php?fid=$1&page=$2
RewriteRule ^thread-([0-9]+)-([0-9]+)-([0-9]+)/.html$ viewthread.php?tid=$1&extra=page/%3D$3&page=$2
RewriteRule ^profile-(username|uid)-(.+)/.html$ viewpro.php?$1=$2
RewriteRule ^space-(username|uid)-(.+)/.html$ space.php?$1=$2
RewriteRule ^tag-(.+)/.html$ tag.php?name=$1
在UCHome中可以这样实现:
RewriteEngine On
RewriteBase /
RewriteRule
^(space|network)/-(.+)/.html$ $1.php?rewrite=$2 [L]
RewriteRule
^(space|network)/.html$ $1.php [L]
RewriteRule ^([0-9]+)$ space.php?uid=$1
[L]