post

设置Windows的httpd.ini实现伪静态

今天突然就想弄一下伪静态,都说windows下的不好弄,可是我的提供商目前还没有Linux主机,遗憾。幸好找到了下面的方法,很管用,我的提供商需要提供httpd.ini文件给他,他们在服务器端设置才可以,这点很差劲,麻烦死了,他们的服务态度还不错。

在非windows的主机下,使用WordPress伪静态,不需要设置那么多东西,只要在程序后台的固定链接里写上自己想要的链接模式就行了,但windows主机下,想用WordPress的伪静态就比较麻烦。

网上常用的是两种方法,一种是用404定义(这个我没用过,具体好不好不清楚,似乎不能支持放在根目录的博客,优势是不需要主机支持什么,只要能自定义404页面,但总感觉对收录之类有些影响,也有人说没事;方法请自行搜索),另一种方法就是用httpd.ini,这需要服务器支持。至于服务器方面需要什么就不在这里说了。

配置httpd.ini的优点:可以实现链接伪静态;
配置httpd.ini的缺点:不完美,主要在分类翻页失效和wap(需要装wap插件)无法静态上;原链接依然存在,即xxx.com/1.html(定义伪静态后的)和xxx.com/?p=1两个地址共存,造成收录重复。
第一个缺点当前无法解决;第二个缺点可以用robots.txt禁止收录来解决,禁止代码:

User-Agent: *
Disallow: /index.php?
Disallow: /?p=*

我手上一套还算完善的httpd.ind的定义:

[ISAPI_Rewrite]
# Protect httpd.ini and httpd.parse.errors files
# from accessing through HTTP
# # 形式:/PostID.html
# # 自定义链接 /%post_id%.html
RewriteRule /Tags/(.*) /index\.php\?tag=$1
RewriteRule /(about|contact|about-copyright|favor|archives|tags|sitemap|link|help|security|%e5%85%b3%e4%ba%8e) /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

效果是日志链接 xxx.com/1.html,页面链接为 xxx.com/about。
如果要大量使用“页面”功能的话,这里需要注意的一点是以下这行:

RewriteRule /(about|contact|about-copyright|favor|archives|tags|sitemap|link|help|security|%e5%85%b3%e4%ba%8e) /index\.php\?pagename=$1

这是定义页面的,增加一个页面就要在这里对应增加这个页面的固定连接后缀,如about。若想加带中文的链接话,不能在这里直接写中文,而需要写中文对应的编码(点页面的“快速编辑”,在“别名”一栏可看到,复制过来即可),如里面的%e5%85%b3%e4%ba%8e。

漏了说使用方法,把其上面那整段的代码复制到记事本里,保存,然后改名为httpd.ini,传到根目录下;在wp后台设置-固定链接处选择自定义结构,填上 %post_id%.html。

补充:在windows主机下要支持httpd.ini就需要安装ISAPI Rewrite组件,当前有2和3两个版本。一般win主机选择的是2,其就会有我在上面所说的翻页问题。若用3则比较完美,但3版本不支持多站点,只能一个站点使用,所以一般idc不考虑这个,若自己的服务器可以这么弄。

转自:摇曳铃丹

Comments

  1. 坐个沙发 嘿嘿

  2. 坐个沙发 嘿嘿

Speak Your Mind

*

· 1,338 次浏览