【问题标题】:Laravel .htaccess rewrite rule conversion to IISLaravel .htaccess 重写规则转换为 IIS
【发布时间】:2013-02-22 06:55:39
【问题描述】:

Laravel4 框架带有一个默认的 .htaccess 规则来创建漂亮的 url。

规则是这样的。

<IfModule mod_rewrite.c>
    Options -MultiViews
    RewriteEngine On
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteRule ^ index.php [L]
</IfModule>

问题: IIS 中的等价物是什么?

【问题讨论】:

    标签: php iis iis-7 url-rewriting laravel


    【解决方案1】:

    您可以使用import Apache rules feature 将 Apache 规则转换为 IIS。

    在你的情况下,它将是:

    或在web.config 文件中:

    <rule name="Imported Rule 1" stopProcessing="true">
        <match url="^" ignoreCase="false" />
        <conditions logicalGrouping="MatchAll">
            <add input="{REQUEST_FILENAME}" matchType="IsFile" ignoreCase="false" negate="true" />
        </conditions>
        <action type="Rewrite" url="index.php" />
    </rule>
    

    【讨论】:

    • @jcadiz 如何添加此代码以及在公共或 htacess 中的位置。请帮忙
    【解决方案2】:

    感谢 Oli Folkerd,这对我有用:

    <?xml version="1.0" encoding="utf-8"?>
    <configuration>
        <system.webServer>
            <rewrite>
                <rules>
                    <rule name="Laravel4" stopProcessing="true">
                        <match url="^" ignoreCase="false" />
                        <conditions logicalGrouping="MatchAll">
                            <add input="{REQUEST_FILENAME}" matchType="IsDirectory" negate="true" />
                            <add input="{REQUEST_FILENAME}" matchType="IsFile" negate="true" />
                        </conditions>
                        <action type="Rewrite" url="index.php" appendQueryString="true" />
                    </rule>
                </rules>
            </rewrite>
        </system.webServer>
    </configuration>
    

    【讨论】:

      【解决方案3】:

      有几个额外的部分值得放在您的 web.config 文件中

      下面的代码允许您使用附加的 PUT 和 DELETE HTTP 动词创建 restfull 控制器,并允许在远程调试服务器时显示 laravel 的自定义错误页面:

      <?xml version="1.0" encoding="utf-8"?>
      <configuration>
          <system.webServer>
              <rewrite>
                  <rules>
                      <rule name="Laravel4" stopProcessing="true">
                          <match url="^" ignoreCase="false" />
                          <conditions logicalGrouping="MatchAll">
                              <add input="{REQUEST_FILENAME}" matchType="IsDirectory" negate="true" />
                              <add input="{REQUEST_FILENAME}" matchType="IsFile" negate="true" />
                          </conditions>
                          <action type="Rewrite" url="index.php" appendQueryString="true" />
                      </rule>
                  </rules>
              </rewrite>
              <handlers>
                  <remove name="PHP53_via_FastCGI" />
                  <add name="PHP53_via_FastCGI" path="*.php" verb="GET,HEAD,POST,PUT,DELETE" modules="FastCgiModule" scriptProcessor="C:\Program Files (x86)\PHP\v5.3\php-cgi.exe" resourceType="Either" requireAccess="Script" />
              </handlers>
              <httpErrors errorMode="Detailed" />
          </system.webServer>
      </configuration>
      

      【讨论】:

        猜你喜欢
        • 2011-04-25
        • 2013-04-10
        • 2020-03-08
        • 2014-01-05
        • 1970-01-01
        • 2013-08-09
        • 2014-06-30
        • 2016-08-09
        • 2012-08-22
        相关资源
        最近更新 更多