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

我在.net面板上托管了一个Laravel应用程序,如果安装在根目录中则可以正常工作。 但是我必须在root之后的两个子目录中使用它,即它安装在root / dir1 / dir2 / app中。 现在,下面是我在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>

因此,目前, http://demo.example.com/dir1/dir2/index.php/login可以正常工作,但我需要像http://demo.example.com/dir1/dir2/login一样吗?可能? 如果是这样,请尽可能多地解释您的答案。 谢谢。

没关系! 我想到了。 实际上,我的父目录的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>

希望这也可以帮助其他人。

暂无
暂无

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

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