dontoften8899 2019-02-14 11:11
浏览 83

在IIS web.config中翻译.htaccess

I am trying to build a MVC app in php in windows server.

My app is working in Linux/Apache with .htaccess file and I am trying to create a web.config file to work with Windows IIS but I can not make it work.

My app's structure is

/app
/public
.htaccess

My basic .htaccess file redirect to /public folder

# Base .htaccess 
<IfModule mod_rewrite.c>
   RewriteEngine on
   RewriteRule ^$ public/ [L]
   RewriteRule (.*) public/$1 [L]
</IfModule>

Inside app folder I have an .htaccess file .

# app folder Options -Indexes

Inside public I redirect everything through index.php file with url parameters

 # 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>

I tried to translate .htaccess through importing tool in URL rewrite and the result is returning 500 error

This is what i get for base rule

<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>

The one inside app folder does not give me any results for Options -Indexes

And this one is for redirecting to index.php from public folder

<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>

Any ideas to resolve this 500 error ? is something in web.config file but I dont know much of IIS.

Any though would be helpful. TIA

  • 写回答

1条回答 默认 最新

  • dornc9470 2019-02-15 05:56
    关注

    Any ideas to resolve this 500 error ? is something in web.config file but I dont know much of IIS.

    As far as I know, the IIS url rewrite rule doesn't contains the same setting like "RewriteBase /public" in .htaccess.

    The IIS's rewriteBase is auto-calculated based on where the rule is defined - so, if you define the rule under the /pubic folder(path) in your site, that becomes the base for those rules.

    So there is no need to set the rewrite base in the url rewrite in the web.config file if you put a special web.config file inside the publc folder.

    评论

报告相同问题?

悬赏问题

  • ¥15 Matlab问题解答有两个问题
  • ¥50 Oracle Kubernetes服务器集群主节点无法访问,工作节点可以访问
  • ¥15 LCD12864中文显示
  • ¥15 在使用CH341SER.EXE时不小心把所有驱动文件删除了怎么解决
  • ¥15 gsoap生成onvif框架
  • ¥15 有关sql server business intellige安装,包括SSDT、SSMS。
  • ¥15 stm32的can接口不能收发数据
  • ¥15 目标检测算法移植到arm开发板
  • ¥15 利用JD51设计温度报警系统
  • ¥15 快手联盟怎么快速的跑出建立模型