【问题标题】:How writing a url rewrite inbound rule for clean URLs for IIS如何为 IIS 的干净 URL 编写 url 重写入站规则
【发布时间】:2019-05-12 14:45:02
【问题描述】:

我在服务器 2012R2 和 IIS 上运行 Typo3。在同一台服务器上还安装了交换。 Typo3 现在创建干净的 URL,但此 URL 总是会创建 404 错误。我找到了解决这个问题的方法

<system.webServer>
    <defaultDocument>
        <files>
            <add value="index.php" />
        </files>
    </defaultDocument>
    <rewrite>
        <rules>
            <rule name="SpeakingURL" enabled="false">
                <match url="(^(typo3|fileadmin|typo3temp|uploads)/|\.(php|js|css|jpg|png|gif|pdf)$)" negate="true" />
                <action type="Rewrite" url="index.php" />
            </rule>
        </rules>
    </rewrite>
</system.webServer>

但交换不再正常工作。所以我必须寻找一种只检测干净 URL 的解决方案。

示例:http;//www.myDomain.com/customers/name/location 这个 URL 我必须发送到 index.php。

url 中没有查询字符串,路径中没有点或任何扩展名。 如何为 IIS URL 重写构建规则,将传入的干净 URL 传递给 index.php?

【问题讨论】:

  • 由于您在同一台IIS服务器上有多个应用程序,请确保您分析不同的URL模式,以便您可以使用不同的规则和正则表达式来区分它们。 URL 重写还支持可以简化某些情况的条件(如 Host 标头)。如果没有更具体的场景,则无法进行讨论。

标签: iis url-rewriting typo3 clean-urls


【解决方案1】:

您的问题是两种虚拟 URL。

我不太了解交换,但我知道 TYPO3。

在 TYPO3 中,您有一些真正的文件夹,用于存放图像、CSS、JS 等文件,并且所有 HTML 都是虚拟的。虽然您有文件的确切路径,但只有您的虚拟内容负责 HTML(虚拟页面)的路径。这使得很难为重写提供修复规则。
在正常的 TYPO3 安装中,您只有那些真实文件,其余的都是虚拟的,由/index.php 处理。 但这仅在您使用 TYPO3 9 或扩展名 realurl(或旧的 simulatestatic)时有效。 否则 TYPO3 仅使用 index.php 并处理 URL 参数中的其余部分(例如 @987654324 @)

解决方案:
禁用 realurl(缺点:没有好的 URL)
或使用扩展名staticfilecache,它将所有 CMS 页面导出为真实文件,因此无需重写(缺点:没有“动态”内容)。

【讨论】:

    【解决方案2】:

    看来,我找到了解决问题的方法。到目前为止,它对我来说很好。 我在 wwwroot 下的 web.config 文件的 system.webServer 部分添加了以下代码。

       <defaultDocument>
            <files>
                <add value="index.php" />
            </files>
        </defaultDocument>
        <rewrite>
            <rules>
                <clear />
                <rule name="Clean URL" enabled="true">
                    <match url="(.*)" />
                    <action type="Rewrite" url="index.php" />
                    <conditions>
                       <add input="{REQUEST_FILENAME}" matchType="IsFile" negate="true" />
                       <add input="{REQUEST_FILENAME}" matchType="IsDirectory" negate="true" />
                   </conditions>
               </rule>
            </rules>
        </rewrite>
    

    这是 Typo3 9,5+

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2023-03-30
      • 2011-04-21
      • 2014-10-27
      • 2012-02-16
      • 1970-01-01
      相关资源
      最近更新 更多