【发布时间】:2013-12-19 06:40:12
【问题描述】:
我使用 PHP 框架 - Codeigniter 2 开发了我的网站。这个网站有一个前端和一个后端。
对于后端,我在网站的根目录中创建了一个名为 webadmin 的目录。
本网站之前使用 APACHE 服务器托管在 LINUX 操作系统上,但最近我们已经转移到使用 IIS 服务器的专用 WINDOWS 操作系统服务器上。
以前在 LINUX 上,我使用 2 个 htaccess 文件,一个在根目录,另一个在我的子目录。它在这两种情况下都运行良好。
现在由于 IIS 服务器,我必须将所有设置导入 IIS Web.config 文件。使用 index.php 的重写规则生成的 web.config 非常适合我的前端,但在我的子目录 http://www.somedomain.com/webadmin 中不起作用。
我在我的根目录中使用了以下 web.config 文件:-
<?xml version="1.0" encoding="UTF-8"?>
<configuration>
<system.webServer>
<rewrite>
<rules>
<rule name="Clean URL" 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="index.php/{R:1}" appendQueryString="true" />
</rule>
</rules>
</rewrite>
<defaultDocument>
<files>
<clear />
<add value="Index.php" />
<add value="Index.html" />
<add value="Index.htm" />
<add value="Index.cfm" />
<add value="Index.shtml" />
<add value="Index.shtm" />
<add value="Index.stm" />
<add value="Index.php3" />
<add value="Index.asp" />
<add value="Index.aspx" />
<add value="Default.htm" />
<add value="Default.asp" />
<add value="Default.aspx" />
</files>
</defaultDocument>
<httpErrors errorMode="Detailed" />
</system.webServer>
</configuration>
接下来是我的子目录中的 web.config 文件,它不起作用并给我 404 错误。
<?xml version="1.0" encoding="UTF-8"?>
<configuration>
<system.webServer>
<security>
<requestFiltering allowDoubleEscaping="true" />
</security>
<rewrite>
<rules>
<rule name="YOURLS" stopProcessing="true">
<match url="^webadmin/(.*)$" ignoreCase="false" />
<conditions>
<add input="{REQUEST_FILENAME}" matchType="IsFile" negate="true" />
<add input="{REQUEST_FILENAME}" matchType="IsDirectory" negate="true" />
</conditions>
<action type="Rewrite" url="/webadmin/index.php/{R:1}" appendQueryString="true" />
</rule>
</rules>
</rewrite>
</system.webServer>
</configuration>
【问题讨论】:
-
拥有一个或多个 web.config 文件也是一种好习惯。 ???
标签: php .htaccess codeigniter iis web-config