专注于discuz,uchome,dedecms等各类PHP程序仿站(二次开发和模板制作)。

« »

WordPress – IIS7伪静态规则 支持中文

这是适用于IIS7及以上的Wordpress的伪静态规则,保存成web.config文件,放到网站根目录即可。

<?xml version=”1.0″ encoding=”UTF-8″?>
<configuration>
<system.webServer>
<rewrite>
<rules>
<rule name=”ChineseURL” stopProcessing=”true”>
<match url=”^(.*)$” />
<conditions>
<add input=”{REQUEST_FILENAME}” matchType=”IsFile” negate=”true” />
<add input=”{REQUEST_FILENAME}” matchType=”IsDirectory” negate=”true” />
</conditions>
<action type=”Rewrite” url=”chineseurl.php”  appendQueryString=”true” />
</rule>
</rules>
</rewrite>
</system.webServer>
</configuration>

新建一个“chineseurl.php”文件:

<?php

// IIS Mod-Rewrite
if (isset($_SERVER['HTTP_X_ORIGINAL_URL'])) {
$_SERVER['REQUEST_URI'] = $_SERVER['HTTP_X_ORIGINAL_URL'];
}else if (isset($_SERVER['HTTP_X_REWRITE_URL'])) {// IIS Isapi_Rewrite
$_SERVER['REQUEST_URI'] = $_SERVER['HTTP_X_REWRITE_URL'];
}else{
// Use ORIG_PATH_INFO if there is no PATH_INFO
if ( !isset($_SERVER['PATH_INFO']) && isset($_SERVER['ORIG_PATH_INFO']) )
$_SERVER['PATH_INFO'] = $_SERVER['ORIG_PATH_INFO'];

// Some IIS + PHP configurations puts the script-name in the path-info (No need to append it twice)
if ( isset($_SERVER['PATH_INFO']) ) {
if ( $_SERVER['PATH_INFO'] == $_SERVER['SCRIPT_NAME'] )
$_SERVER['REQUEST_URI'] = $_SERVER['PATH_INFO'];
else
$_SERVER['REQUEST_URI'] = $_SERVER['SCRIPT_NAME'] . $_SERVER['PATH_INFO'];
}

// Append the query string if it exists and isn’t null
if (isset($_SERVER['QUERY_STRING']) && !empty($_SERVER['QUERY_STRING'])) {
$_SERVER['REQUEST_URI'] .= ‘?’ . $_SERVER['QUERY_STRING'];
}
}

require(“index.php”);

?>

原创文章如转载,请注明:转载自火跃工作室
本文网址:http://www.huoyue.org/wordpress-iis-url-rewrite-web-config

日志信息 »

该日志于2014-07-18 22:56由 火跃 发表在PHP+mysql分类下, 评论已关闭。

相关日志 »

没有评论

抱歉,评论被关闭