简体   繁体   English

如何在web.config文件中重写URL以将index.php隐藏在类似http://demo.example.com/dir/dir/index.php/login的URL中?

[英]How to Rewrite URL in web.config file to hide index.php in url like http://demo.example.com/dir/dir/index.php/login?

I have a Laravel app hosted on a .net panel, which works fine if installed in the root. 我在.net面板上托管了一个Laravel应用程序,如果安装在根目录中则可以正常工作。 But I have to use it inside of two sub-directories after root, ie it's installed in root/dir1/dir2/app. 但是我必须在root之后的两个子目录中使用它,即它安装在root / dir1 / dir2 / app中。 Now below is my current code in the web.config file which works fine if the app is installed directly in the root directory: 现在,下面是我在web.config文件中的当前代码,如果该应用程序直接安装在根目录中,则可以正常运行:

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

So, currently, http://demo.example.com/dir1/dir2/index.php/login works, but I need it to be like http://demo.example.com/dir1/dir2/login , is it possible? 因此,目前, http://demo.example.com/dir1/dir2/index.php/login可以正常工作,但我需要像http://demo.example.com/dir1/dir2/login一样吗?可能? If so, please explain your answer as much as possible. 如果是这样,请尽可能多地解释您的答案。 Thanks. 谢谢。

Nevermind! 没关系! I figured it out. 我想到了。 Actually, my parent directory's web.config was conflicting with the sub-dir web.config file, so I added <clear /> after the <rules> tag in both of them and now it's working fine. 实际上,我的父目录的web.config与子目录web.config文件冲突,因此我在两个文件的<rules>标记后添加了<clear /> ,现在一切正常。 Check out the below final code that works: 查看以下有效的最终代码:

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

Hope this might help someone else too. 希望这也可以帮助其他人。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM