如何在web上重写URL。配置文件隐藏索引。如http://demo.example.com/dir/dir/index.php/login?

时间:2022-11-24 00:20:52

I have a Laravel app hosted on a .net panel, which works fine if installed in the root. But I have to use it inside of two sub-directories after root, i.e. it's installed in 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:

我有一个在.net面板上托管的Laravel应用程序,如果安装在根目录下,它可以正常工作。但我必须在根目录下的两个子目录中使用它,也就是说它安装在根/dir1/dir2/app中。下面是我在web上的当前代码。如果应用程序直接安装在根目录下,配置文件可以正常工作:

<?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? If so, please explain your answer as much as possible. Thanks.

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

1 个解决方案

#1


0  

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. Check out the below final code that works:

别介意!我想出来。实际上,我的父目录的web。配置与子目录web相冲突。配置文件,所以我添加了 ,在 标签之后,现在它运行良好。查看下面的最终代码:

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

希望这对其他人也有帮助。

#1


0  

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. Check out the below final code that works:

别介意!我想出来。实际上,我的父目录的web。配置与子目录web相冲突。配置文件,所以我添加了 ,在 标签之后,现在它运行良好。查看下面的最终代码:

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

希望这对其他人也有帮助。