>我使用 PHP 框架 - Codeigniter 2 开发了我的网站。这个网站有一个前端和一个后端。
对于后端,我在网站的根目录中创建了一个名为webadmin的目录。
这个网站以前是使用APACHE服务器托管在LINUX OS上的,但最近我们已经转向使用IIS服务器的专用WINDOWS操作系统服务器。
以前在 LINUX 上使用 2 个 htaccess 文件,一个在根目录中,另一个在我的子目录中。它在这两种情况下都运行良好。
现在由于IIS服务器,我不得不将所有设置导入IIS Web.config文件。生成的 web.config 非常适合我的前端,具有 index.php 的重写规则,但在我 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>
这是我使用的版本,对我有用。只需将子域替换为您的。请记住将base_url更改为配置中带有子域的。
<?xml version="1.0" encoding="UTF-8"?>
<configuration>
<system.webServer>
<rewrite>
<rules>
<rule name="Rewrite to index.php">
<match url="index.php|robots.txt|images|test.php" />
<action type="None" />
</rule>
<rule name="Rewrite CI Index">
<match url=".*" />
<conditions>
<add input="{REQUEST_FILENAME}" pattern="css|js|jpg|jpeg|png|gif|ico|htm|html|ttf|woff" negate="true" />
</conditions>
<action type="Rewrite" url="index.php/SUBDOMAIN/{R:0}" />
</rule>
</rules>
</rewrite>
</system.webServer>
</configuration>