2016-08-30 61 views
0

我有一个.net面板托管的Laravel应用程序,如果安装在根目录下,它工作正常。但是我必须在根目录后面的两个子目录中使用它,即它安装在root/dir1/dir2/app中。现在下面是我目前在web.config文件中的代码,如果应用程序直接安装在根目录下的正常工作:如何在web.config文件中重写URL以隐藏url中的index.php,例如http://demo.example.com/dir/dir/index.php/login?

<?xml version="1.0" encoding="UTF-8"?> 
<configuration> 
    <system.webServer> 
     <rewrite> 
      <rules> 
       <rule name="Move to index.php"> 
        <match url=".*" /> 
        <conditions> 
         <add input="{REQUEST_FILENAME}" matchType="IsFile" negate="true" /> 
         <add input="{REQUEST_FILENAME}" matchType="IsDirectory" negate="true" /> 
        </conditions> 
        <action type="Rewrite" url="index.php/{R:0}" logRewrittenUrl="true" /> 
       </rule> 
      </rules> 
     </rewrite> 
     <httpProtocol> 
      <customHeaders> 
       <add name="X-UA-Compatible" value="IE=11" /> 
      </customHeaders> 
     </httpProtocol> 
    </system.webServer> 
</configuration> 

所以,目前,http://demo.example.com/dir1/dir2/index.php/login的作品,但我需要它像http://demo.example.com/dir1/dir2/login,是有可能吗?如果是这样,请尽可能解释您的答案。 谢谢。

回答

0

没关系!我想到了。实际上,我的父目录的web.config与子目录web.config文件冲突,所以我在<rules>标签之后添加了<clear />,现在它工作正常。看看下面最后的代码:

<?xml version="1.0" encoding="UTF-8"?> 
<configuration> 
    <system.webServer> 
     <rewrite> 
      <rules> 
       <clear /> 
       <rule name="Move to index.php"> 
        <match url=".*" /> 
        <conditions> 
         <add input="{REQUEST_FILENAME}" matchType="IsFile" negate="true" /> 
         <add input="{REQUEST_FILENAME}" matchType="IsDirectory" negate="true" /> 
        </conditions> 
        <action type="Rewrite" url="index.php/{R:0}" logRewrittenUrl="true" /> 
       </rule> 
      </rules> 
     </rewrite> 
     <httpProtocol> 
      <customHeaders> 
       <add name="X-UA-Compatible" value="IE=11" /> 
      </customHeaders> 
     </httpProtocol> 
    </system.webServer> 
</configuration> 

希望这可能也会帮助其他人。