首页 > 解决方案 > URL 从尾随字符串重写为 GET 变量

问题描述

我已经搜索过这个,但似乎无法找到正确的搜索词 - 似乎这将是一个常见问题。

WIMP,IIS版本为8

我想提出一个重写规则:传入 URL: http ://example.com/1a2b3cdef 重写为:http ://example.com?p=1a2b3cdef

请注意,此 URL 的开头将始终是“http://example.com/”(不是真正的域名),永远不会改变。

从那里我的 index.php 的默认文档将检索 GET 变量 p。任何帮助是极大的赞赏。

标签: url-rewritingiis-8

解决方案


这是可以在 web.config 中应用的配置。

<defaultDocument>

            <files>

                <add value="index.php" />

            </files>

        </defaultDocument>

        <rewrite>

            <rules>

                <rule name="rewrite" enabled="true">

                    <match url="^[_0-9a-z]+" />

                    <action type="Rewrite" url="?p={R:0}" />

                </rule>

            </rules>

        </rewrite>

推荐阅读