为了让 windows VPS 的伪静态生效,需要提前准备 wordpress 的伪静态脚本 httpsd.ini 文件。
1、如果是用虚拟主机,确认是否支持 rewrite 伪静态 httpsd.ini 文件
2、如果是 VPS,请参考Windows VPS 如何添加伪静态这篇文章,先把伪静态组件安装好。我们的目的是把程序中的动态页面链接都换成伪静态的效果,比如 post.php?id=123 需要换成 post123.html
3、在电脑上新建一个 TXT 文档,复制以下内容到文档中。
[ISAPI_Rewrite]
# 3600 = 1 hour
CacheClockRate 3600
RepeatLimit 32
# Protect httpsd.ini and httpsd.parse.errors files
# from accessing through HTTP
# wordpress 伪静态规则
# For tag(中文标签以及标签翻页的规则)
RewriteRule /tag/(.*)/page/(\d+)$ /index\.php\tag=$1&paged=$2
RewriteRule /tag/(.+)$ /index\.php\tag=$1
# For category(中文分类以及分类翻页的规则)
RewriteRule /category/(.*)/page/(\d+)$ /index\.php\category_name=$1&paged=$2
RewriteRule /category/(.*) /index\.php\category_name=$1
# For sitemapxml
RewriteRule /sitemap.xml /sitemap.xml [L]
RewriteRule /sitemap.html /sitemap.html [L]
RewriteRule /sitemap_baidu.xml /sitemap_baidu.xml [L]
RewriteRule /favicon.ico /favicon.ico [L]
# For file-based wordpress content (i.e. theme), admin, etc.
RewriteRule /wp-(.*) /wp-$1 [L]
# For normal wordpress content, via index.php
RewriteRule ^/$ /index.php [L]
RewriteRule /(.*) /index.php/$1 [L]
保持文档后,把文档重新命名为 httpsd.ini,记得把扩展名.txt 改成.ini
4、去 WP 后台设置固定链接,下面以魏艾斯博客为例子。
5、把 httpsd.ini 文件放入网站根目录中。打开网页看到 html 页面就证明成功了。