【发布时间】:2019-02-14 11:11:51
【问题描述】:
我正在尝试在 windows 服务器的 php 中构建一个 MVC 应用程序。
我的应用程序正在使用 .htaccess 文件在 Linux/Apache 中运行,我正在尝试创建一个 web.config 文件以使用 Windows IIS,但我无法使其运行。
我的应用结构是
/app
/public
.htaccess
我的基本.htaccess 文件重定向到/public 文件夹
# Base .htaccess
<IfModule mod_rewrite.c>
RewriteEngine on
RewriteRule ^$ public/ [L]
RewriteRule (.*) public/$1 [L]
</IfModule>
在 app 文件夹中,我有一个 .htaccess 文件。
# app folder
Options -Indexes
在公共内部,我通过带有 url 参数的 index.php 文件重定向所有内容
# public folder
<IfModule mod_rewrite.c>
Options -Multiviews
RewriteEngine On
RewriteBase /public
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(.+)$ index.php?url=$1 [QSA,L]
</IfModule>
我尝试通过URL重写中的导入工具翻译.htaccess,结果返回500 error
这是我得到的基本规则
<rewrite>
<rules>
<rule name="Imported Rule 1" stopProcessing="true">
<match url="^$" ignoreCase="false" />
<action type="Rewrite" url="public/" />
</rule>
<rule name="Imported Rule 2" stopProcessing="true">
<match url="(.*)" ignoreCase="false" />
<action type="Rewrite" url="public/{R:1}" />
</rule>
</rules>
</rewrite>
app 文件夹中的那个没有给我Options -Indexes 的任何结果
这个是从公共文件夹重定向到 index.php
<rewrite>
<!--This directive was not converted because it is not supported by IIS: RewriteBase /public.-->
<rules>
<rule name="Imported Rule 3" stopProcessing="true">
<match url="^(.+)$" ignoreCase="false" />
<conditions>
<add input="{REQUEST_FILENAME}" matchType="IsDirectory" ignoreCase="false" negate="true" />
<add input="{REQUEST_FILENAME}" matchType="IsFile" ignoreCase="false" negate="true" />
</conditions>
<action type="Rewrite" url="index.php?url={R:1}" appendQueryString="true" />
</rule>
</rules>
</rewrite>
有什么办法可以解决这个 500 错误吗?是 web.config 文件中的东西,但我不太了解 IIS。
虽然会有帮助。 TIA
【问题讨论】:
标签: php .htaccess iis web-config