URL从尾随字符串重写为GET变量

问题描述

我已经进行了搜索,但似乎找不到合适的搜索词来查找-这似乎是一个常见问题。

WIMP,IIS版本为8

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

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

从那里,我的认文档index.PHP将检索GET变量p。 任何帮助将不胜感激。

解决方法

这是可以在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>