2013-02-22 73 views
11

Laravel4框架附帶默認的.htaccess規則,用於創建漂亮的URL。Laravel .htaccess將重寫規則轉換爲IIS

規則是這樣的。

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

問題:這是相當於在IIS中?

回答

8

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

2

有幾個是值得投入在你的網頁的額外部分。配置文件

下面的代碼允許您使用附加的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> 
4

這個工作對我來說,這要歸功於奧利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>