我试图在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
在公共内部,我通过index.php文件重定向所有内容和url参数
# 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
有什么想法来解决这500错误吗?是web.config文件中的东西,但我不太了解IIS。
据我所知,IIS url重写规则不包含与.htaccess中的“RewriteBase / public”相同的设置。
IIS的rewriteBase是根据规则的定义位置自动计算的 - 因此,如果您在站点的/ pubic文件夹(路径)下定义规则,那么这将成为这些规则的基础。
因此,如果在publc文件夹中放置一个特殊的web.config文件,则无需在web.config文件中的url rewrite中设置重写基础。