一般我们使用wordpress都会将固定链接设置成伪静态的,但是WP却只能在LINUX系统的服务器中才能很好的使用,在WINDOWS系统的IIS中设置伪静态会在前面加上index.php,所以无法实现真正的伪静态功能。
win主机下的wordpress文章的链接都是http://www.***.com/index.php/123.html类似的链,
中间的index.php异常明显
这里介绍两种方法
第一种,用404.php实现伪静态
1、进入WP后台,【设置】--【固定连接】里面,先把固定连接选择自定义,设置成/%post_id%.html。
2、上传下面的404.php页面到网站根目录下,然后在虚拟主机控制面板里面修改404跳转页面为刚才上传的404.php,这样就可以实现伪静态了。
第二种,首页你的主机要装Rewrite 组件,现在国内很多WINDOWS主机都有装这个了。
使用方法:下载下面的httd.ini文件,直接上传到网站的根目录。然后去WP后台设置固定连接:/%post_id%.html
然后在httpd.ini 中加入如下代码:
[ISAPI_Rewrite]
# 3600 = 1 hour
CacheClockRate 3600
RepeatLimit 32
# Protect httpd.ini and httpd.parse.errors files
# from accessing through HTTP
# Rules to ensure that normal content gets through
RewriteRule /sitemap.xml /sitemap.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]
如果用了第二种方法导致百度地图链接打不开请添加以下两句代码:
RewriteRule /sitemap.html /sitemap.html [L]
RewriteRule /sitemap_baidu.xml /sitemap_baidu.xml [L]
第三种方式:另外一个比较具体的写法,如果用第二个有问题,可以尝试这个
[ISAPI_Rewrite]
# 3600 = 1 hour
CacheClockRate 3600
RepeatLimit 32
# Protect httpd.ini and httpd.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]