Laravel .htaccess将重写规则转换为IIS

问题描述:

Laravel4框架附带默认的.htaccess规则,用于创建漂亮的URL。Laravel .htaccess将重写规则转换为IIS

规则是这样的。

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

问题:这是相当于在IIS中?

您可以使用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> 
+0

非常有用的,谢谢。 – 2013-03-04 22:12:01

+0

@jcadiz如何添加此代码以及在公共或htacess中的位置。请帮忙 – 2013-08-05 19:01:27

有几个是值得投入在你的网页的额外部分。配置文件

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

<?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> 

这个工作对我来说,这要归功于奥利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>