Laravel .htaccess 重写规则转换为 IIS
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/15018538/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Laravel .htaccess rewrite rule conversion to IIS
提问by Javier Cadiz
Laravel4 framework comes with a default .htaccess rule for create pretty urls.
Laravel4 框架带有一个默认的 .htaccess 规则来创建漂亮的 url。
The rule is this.
规则是这样的。
<IfModule mod_rewrite.c>
Options -MultiViews
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^ index.php [L]
</IfModule>
Question:Which is the equivalent in IIS ??
问题:IIS 中的等价物是什么?
采纳答案by cheesemacfly
You can use the import Apache rules featureto convert Apache rule to IIS.
您可以使用导入 Apache 规则功能将 Apache 规则转换为 IIS。
In your case, it will go as:
在您的情况下,它将如下所示:
Or in the web.config
file:
或者在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>
回答by DanielRTRD
This worked for me, thanks to Oli Folkerd:
这对我有用,感谢 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>
回答by Oli Folkerd
There are a couple of extra sections that are worth putting in your web.config file
有几个额外的部分值得放在你的 web.config 文件中
The code below allows you to create restfull controllers using the additional PUT and DELETE HTTP verbs, and allows for laravel's custom error pages to be displayed when you are remotley debugging the server:
下面的代码允许您使用附加的 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>