【问题标题】:Translate .htacess in IIS web.config在 IIS web.config 中翻译 .htaccess
【发布时间】: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


    【解决方案1】:

    有什么办法可以解决这个 500 错误吗?是 web.config 文件中的东西,但我不太了解 IIS。

    据我所知,IIS url 重写规则不包含与 .htaccess 中的“RewriteBase /public”相同的设置。

    IIS 的 rewriteBase 是根据定义规则的位置自动计算的 - 因此,如果您在站点的 /pubic 文件夹(路径)下定义规则,它将成为这些规则的基础。

    所以如果你在publc文件夹中放了一个特殊的web.config文件,那么web.config文件中的url rewrite就不需要设置rewrite base了。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2012-01-30
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2014-12-14
      • 1970-01-01
      • 2012-02-15
      相关资源
      最近更新 更多