当前位置: 移动技术网 > 网络运营>服务器>Windows > IIS环境下PHP rewrite重写设置(支持中文参数)

IIS环境下PHP rewrite重写设置(支持中文参数)

2019年04月18日  | 移动技术网网络运营  | 我要评论

在网站根目录下加入:

web.config:

<?xml version="1.0" encoding=”utf-8″?>
<configuration>
  <system.webserver>
    <rewrite>
     <rules>
      <rule name="cnurl" stopprocessing="true">
       <match url="!^(index\.php|images|assets|robots\.txt)" />
       <action type="rewrite" url="cnurl.php" />
      </rule>
      <rule name="default" patternsyntax="wildcard">
       <match url="*" />
        <conditions>
         <add input="{request_filename}" matchtype="isfile" negate="true" />
         <add input="{request_filename}" matchtype="isdirectory" negate="true" />
        </conditions>
       <action type="rewrite" url="index.php" />
      </rule>
     </rules>
    </rewrite>
  </system.webserver>
</configuration>

cnurl.php:

<?php
if (isset($_server['http_x_original_url'])) {
  // iis mod-rewrite
  $_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
  (!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'])) {
    ($_server['path_info'] == $_server['script_name']) ? ($_server['request_uri'] = $_server['path_info']) : ($_server['request_uri'] = $_server['script_name'] . $_server['path_info']);
  }
  // append the query string if it exists and isn't null
  (isset($_server['query_string']) && !empty($_server['query_string'])) && ($_server['request_uri'] .= '?' . $_server['query_string']);
}
require("index.php");

支持iis环境下跑各种开源php项目,如:wordpress、emlog、typecho等。

如对本文有疑问, 点击进行留言回复!!

相关文章:

验证码:
移动技术网