WordPress3在IIS下的URL伪静态配置

1.新建记事本(或者DreamWeaver新建一个php文件),在里面写入以下代码,保存,连同txt格式重新命名为404.php。将404.php上传到你的网站根目录。即:/web/下

< ?php

header("HTTP/1.1 200 OK");

$ori_qs = strtolower($_SERVER['QUERY_STRING']);

$pattern = '/[^;]+;[^:]+://[^/]+(/[^?]*)(?:?(.*))?/i';

preg_match($pattern, $ori_qs, $matches);

$_SERVER['PATH_INFO'] = $matches[1] . '?' . $matches[2];

$_SERVER['REQUEST_URI'] = $_SERVER['PATH_INFO'];

$query_args = explode('&', $matches[2]);

unset($_GET);

foreach ($query_args as $arg)

{

$the_arg = explode('=', $arg);

$_GET[$the_arg[0]] = $the_arg[1];

}

include('index.php');

?>

2.设置404自定义错误指向404.php,一般来说,绝大多数虚拟主机提供商都是支持的,具体设置404页面的方法因虚拟主机管理系统不同略有差异,不明白怎么设置的可以找主机客服帮忙。

3.进入WordPress3.0.1 管理后台,【设置】→【永久链接】→【自定义结构】,随意设置自己喜欢的伪静态地址格式及静态地址后缀。

例如:

/y%year%/%post_id%.html

/%year%/%monthnum%/%post_id%.html

/%year%/%monthnum%/%postname%.html

使用的格式就是:/%post_id%.html

到这里还没有完,这样并非完美。因为到这里所有的中文Tag页面仍然会出错,跳转到404页面,解决办法如下:

建议用DW打开wp-includes/classes.php文件,找到如下代码(注意红色代码,在第154行160行):

if ( isset($_SERVER['PATH_INFO']) )

$pathinfo = $_SERVER['PATH_INFO'];

else

$pathinfo = '';$pathinfo_array = explode('?', $pathinfo);

$pathinfo = str_replace("%", "%", $pathinfo_array[0]);

$req_uri = $_SERVER['REQUEST_URI'];

替换为:

if ( isset($_SERVER['PATH_INFO']) )

$pathinfo = iconv('GBK', 'UTF-8', $_SERVER['PATH_INFO']);

else $pathinfo = '';$pathinfo_array = explode('?', $pathinfo);

$pathinfo = str_replace("%", "%", $pathinfo_array[0]);

$req_uri = iconv('GBK', 'UTF-8', $_SERVER['REQUEST_URI']);

 当然走到这步他们说是算是已经可以达到伪静态了“`但是我却不能如愿“`因为按照他们的说法刚才设置了404页面“我进入某页面无法打开已经直接跳转到404.php这个页面了“显示这刚才的那些404代码“`

显示:< ?php header("HTTP/1.1 200 OK"); $ori_qs = strtolower($_SERVER['QUERY_STRING']); $pattern = '/[^;]+;[^:]+://[^/]+(/[^?]*)(?:?(.*))?/i'; preg_match($pattern, $ori_qs, $matches); $_SERVER['PATH_INFO'] = $matches[1] . '?' . $matches[2]; $_SERVER['REQUEST_URI'] = $_SERVER['PATH_INFO']; $query_args = explode('&', $matches[2]); unset($_GET); foreach ($query_args as $arg) { $the_arg = explode('=', $arg); $_GET[$the_arg[0]] = $the_arg[1]; } include('index.php'); ?>

如果你走到这步可以正常访问内页“那么下面的造作你就可以不要看了“我这边按照他们的说法是不能访问“所以我进行了修改“`找到了一些新的代码“

请记住量子场那个网站使用的虚拟主机是Windows+iis+MySql+Php“`所以再加一步就OK了“

看好哦“呵呵“首先,大家要了解当前虚拟主机是否支持ISAPI_Rewrite伪静态,其次要把下列代码复制并粘贴到TXT文本里面并更改整个文件名称为httpd.ini,之后上传到空间根目录下。即:/web/下

 

 

[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]

 

复制以上代码到TXT并更改文件名为httpd.ini,上传至空间根目录下。即:/web/

 

#IIS ISAPI_Rewrite For WordPress:

[ISAPI_Rewrite]

# # 形式:年/月/日/Postname.html
# # 自定义链接 /%year%/%monthnum%/%day%/%postname%.html
# # URL:http://www.dengjin.com

RewriteRule /tag/(.*) /index.php?tag=$1
RewriteRule /(about|contact|about-copyright|favor|archives|tags|sitemap)/ /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 /feed/?$ /wp-feed.php/?feed=rss2
RewriteRule /comments/feed/?$ /wp-feed.php/?feed=comments-rss2
RewriteRule /page/(.*)/ /index.php?paged=$1
RewriteRule /([0-9]{4})/([0-9]{1,2})/([0-9]{1,2})/([^/]+)/?([0-9]+)?.html/?$ /index.php?year=$1&monthnum=$2&day=$3&name=$4&page=$5
RewriteRule /([0-9]{4})/([0-9]{1,2})/([0-9]{1,2})/?$ /index.php?year=$1&monthnum=$2&day=$3&page=$4
RewriteRule /([0-9]{4})/([0-9]{1,2})/?$ /index.php?year=$1&monthnum=$2&page=$3
RewriteRule /([0-9]{4})/([0-9]{1,2})/([0-9]{1,2})/([^/]+).html/(feed|rdf|rss|rss2|atom)/?$ /index.php?year=$1&monthnum=$2&day=$3&name=$4&feed=$5
RewriteRule /([0-9]{4})/([0-9]{1,2})/([0-9]{1,2})/([^/]+).html/trackback/?$ /wp-trackback.php?year=$1&monthnum=$2&day=$3&name=$4&tb=1

# # 形式:年/月/日/Postname/
# # 自定义链接 /%year%/%monthnum%/%day%/%postname%/
# # URL:http://www.dengjin.com

RewriteRule /tag/(.*) /index.php?tag=$1
RewriteRule /(about|contact|about-copyright|favor|archives|tags|sitemap)/ /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 /feed/?$ /wp-feed.php/?feed=rss2
RewriteRule /comments/feed/?$ /wp-feed.php/?feed=comments-rss2
RewriteRule /page/(.*)/ /index.php?paged=$1
RewriteRule /([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 /([0-9]{4})/([0-9]{1,2})/([0-9]{1,2})/?$ /index.php?year=$1&monthnum=$2&day=$3&page=$4
RewriteRule /([0-9]{4})/([0-9]{1,2})/?$ /index.php?year=$1&monthnum=$2&page=$3
RewriteRule /([0-9]{4})/([0-9]{1,2})/([0-9]{1,2})/([^/]+)/(feed|rdf|rss|rss2|atom)/?$ /index.php?year=$1&monthnum=$2&day=$3&name=$4&feed=$5
RewriteRule /([0-9]{4})/([0-9]{1,2})/([0-9]{1,2})/([^/]+)/trackback/?$ /wp-trackback.php?year=$1&monthnum=$2&day=$3&name=$4&tb=1

# # 形式:/post/PostID.html
# # 自定义链接 /post/%post_id%.html
# # URL:http://www.dengjin.com

RewriteRule /post/tag/(.*) /index.php?tag=$1
RewriteRule /tag/(.*) /index.php?tag=$1
RewriteRule /(about|contact|about-copyright|favor|archives|tags|sitemap|taotao) /index.php?pagename=$1
RewriteRule /post/category/(.*)/(feed|rdf|rss|rss2|atom)/?$ /wp-feed.php?category_name=$1&feed=$2
RewriteRule /post/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]+)/?([0-9]+)?/?$ /index.php?p=$1&page=$2
# RewriteRule /post/([0-9]+)/?([0-9]+)?/?$ /index.php?p=$1&page=$2
RewriteRule /post/([0-9]+).html /index.php?p=$1
RewriteRule /page/(.*)/?s=(.*) /index.php?s=$2&paged=$1
RewriteRule /page/(.*) /index.php?paged=$1
RewriteRule /post/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 /post/date/([0-9]{4})/([0-9]{1,2})/([0-9]{1,2})/?$ /index.php?year=$1&monthnum=$2&day=$3&page=$4
RewriteRule /post/date/([0-9]{4})/([0-9]{1,2})/?$ /index.php?year=$1&monthnum=$2&page=$3
RewriteRule /post/([0-9]+).html/(feed|rdf|rss|rss2|atom) /index.php?feed=rss2&p=$1
RewriteRule /post/([0-9]+).html/trackback /wp-trackback.php?p=$1

给本文评个分吧:)

 

[ratings]


 

 

0

扫描到手机上阅读:

QR:  WordPress3在IIS下的URL伪静态配置