【问题标题】:IIS URL Rewrite for Laravel Application Not working for multiple URI SegmentsLaravel 应用程序的 IIS URL 重写不适用于多个 URI 段
【发布时间】:2020-12-15 14:06:22
【问题描述】:

我有一个场景,如果 URL 在 URI 段中不包含任何内容,则无需重写 index.php,但如果包含则重写它。

例如:http://www.example.com/http://www.example.com 不需要重写规则

但如果 URL 是 http://www.example.com/homepagehttp://www.example.com/user/1http://www.example.com/edit-user/123/456 那么它应该被重写为 index.php

我在下面试过了。

<rules>
    <rule name="custom rule 1" stopProcessing="true">
    <match url="^([^/]+)/?$"  />
    <action type="Rewrite" url="index.php"  />
</rule>

它适用于 http://www.example.com/http://www.example.com/homepage,但其他页面显示 404。

URI 段是动态的,可以是多语言的。

使用的技术 IIS、PHP (Laravel)

【问题讨论】:

    标签: regex laravel iis url-rewriting url-rewrite-module


    【解决方案1】:

    你可以试试这个,它会匹配各种 URI,无论是动态的还是多语言的。

     <rule name="custom rule">
                        <match url=".*" />
                        <action type="Rewrite" url="index.php" />
                        <conditions>
                            <add input="{REQUEST_URI}" pattern=".*" />
                       </conditions>
                    </rule>
    

    Test result

    Fail request tracing

    如果这条规则只用于一些URI,比如user或edit-user,也许这条规则更合适。

    <rule name="custom rule">
                    <match url=".*" />
                    <action type="Rewrite" url="index.php" />
                    <conditions logicalGrouping="MatchAny">
                        <add input="{REQUEST_URI}" pattern="user/(.*)" />
                        <add input="{REQUEST_URI}" pattern="edit-user/(.*)" />
                    </conditions>
                </rule>
    

    【讨论】:

    • 以上abcexample.com也处于这种状态
    • 你的意思是abcexample.com也重写为example.com/index.php吗?你可以设置服务器变量HTTP_HOST。
    • 还是同样的问题。我在问题中提到的一条规则工作正常,除了多个请求 uri
    • 您能否更详细地描述问题?我提供的规则已经测试成功。你应用它会失败吗?判断uri的最好方法是条件。
    • 请问您的问题是否解决了?如果我的回答对你有帮助,请标记这个答案,以便帮助其他有类似问题的人。
    猜你喜欢
    • 2014-10-14
    • 2012-12-01
    • 1970-01-01
    • 2021-08-03
    • 1970-01-01
    • 2014-05-06
    • 2021-10-15
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多