【问题标题】:Need a web.config file instead of .htaccess for codeignitercodeigniter 需要一个 web.config 文件而不是 .htaccess
【发布时间】:2014-08-28 18:30:23
【问题描述】:

无论我如何尝试,我仍然无法让 web.config 文件正常工作,它仍然不会重定向到其他页面。我正在使用 codeigniter 并将应用程序托管在 IIS 平台中,这是我的 .htaccess 文件,请问有人可以将此代码转换为 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>

【问题讨论】:

    标签: php .htaccess codeigniter mod-rewrite iis


    【解决方案1】:

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

    <?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 路径。

    【讨论】:

    • 感谢您的快速回复,我会试试这个,如果出现任何错误,请告诉您。
    • 嘿 Barnabas 谢谢伙计,它成功了,我之前使用过类似的,但没有成功,我猜我之前搞砸了重写路径,但无论如何现在我明白了 web.config文件有效,谢谢:)
    • 请告诉我用 IIS 将这个文件放在 codeIgniter 的什么位置
    • @MukeshMohan 如果我没记错的话,它必须转到根文件夹。我希望我是对的。 :)
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-08-19
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-12-25
    • 1970-01-01
    相关资源
    最近更新 更多