需要 web.config 文件而不是 codeigniter 的 .htaccess

2021-12-21 00:00:00 php codeigniter iis .htaccess mod-rewrite

我仍然无法让 web.config 文件工作,无论我如何尝试它仍然无法重定向到其他页面.我正在使用 codeigniter 并在 IIS 平台上托管应用程序,这里是我的 .htaccess 文件,请问有人可以将此代码转换为 web.config 吗?

I still not able to get the web.config file working no matter how I try it still does not redirect to other pages. I am using codeigniter and hosting the application in IIS platform here is my .htaccess file, please can anyone convert this code to web.config?

<IfModule mod_rewrite.c>
  RewriteEngine On
  RewriteBase /travel/
  RewriteCond %{REQUEST_FILENAME} !-f
  RewriteCond %{REQUEST_FILENAME} !-d
  RewriteRule ^(.*)$ index.php?/$1 [L]
</IfModule>

<IfModule !mod_rewrite.c>
  ErrorDocument 404 /index.php
</IfModule>

推荐答案

您的 web.config 文件应如下所示:

Your web.config file should look something like this:

<?xml version="1.0" encoding="UTF-8"?>
<configuration>
<system.webServer>
    <rewrite>
        <rules>
            <rule name="Index">
                <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}"/>
            </rule>                
        </rules>
    </rewrite>
    <httpErrors>
        <remove statusCode="404" subStatusCode="-1" />                
        <error statusCode="404" path="/somedir/oops404.htm" responseMode="ExecuteURL" />                       
    </httpErrors>      
</system.webServer>

在 web.config 文件中未按原样使用 RewriteBase,因此您可能需要相应地更改 URL 路径.

RewriteBase is not used in web.config files as is, so you may need to change the URL paths accordingly.

相关文章