自定义结构可以用你自己喜欢的,比如可以只用用“/%post_id%.html”,这样的访问地址就会是“http://xxx.com/id.html”;当然你也可以用“/%post_id%”,这样的访问地址就会是“http://xxx.com/id/”等等,后缀名“html”也可随便修改,官方提供了如下一些参数。
%year% 年份
%monthnum% 月份
%day% 日期
%hour% 小时
%minute% 分钟
%second% 秒
%postname% 文章名
%post_id% 文章的ID
%category% 目录
%author% 作者
修改好你需要的伪静态后,就要保存更改。然后要为博客的根目录添加一个“httpd.ini”文件,文件创建方法为新建一记事本,另存为httpd.ini,代码如下。
[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 /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]
这样就可以支持伪静态了,但是还不支持中午,需要支持中文还需要修改一个文件,“wp-include”目录下的“class-wp.php”文件。
亲测5.4版本这样修改,其他版本也可以类似这样修改!
第一步:找到
$pathinfo = isset( $_SERVER['PATH_INFO'] ) ? $_SERVER['PATH_INFO'] : '';
修改为:
$pathinfo = mb_convert_encoding($_SERVER['PATH_INFO'], "UTF-8", "GBK");'';
第二步:找到
list( $req_uri ) = explode( '?', $_SERVER['REQUEST_URI'] );
修改为:
list( $req_uri ) = mb_convert_encoding($_SERVER['REQUEST_URI'], "UTF-8", "GBK");
就这样,自己可以支持中文的伪静态状况了,TAG标签页等都可以打开了的。
目前仍然有缺陷,就是文章的分类目录是支持中文的,但是在点击下一页之后,它会爆出找不到页面的错误,连接中本应是分类名称的中文变成了乱码。在规则上没找到合适的办法,所以就先将分类目录的别名改为了英文的名字,注意是别名不是本身的名字。