2

我有一个这样的网址:

http://www.example.com/erf4d

(其中 erf4d 可以是任何 5 个字符的字符串)

我想将用户重定向到:

http://www.example.com/viewentry.aspx?ID=erf4d

我已经使用 web.config 中的重写规则完成了这项工作,但是我希望 http://www.example.com/erf4d保留在 URL 栏中,这样用户就不会看到“丑陋”的 viewentry.aspx? ID=erf4d 一种重定向掩码,如果你愿意的话。有没有办法做到这一点?

4

1 回答 1

3

根据我的经验,URL 重写是反过来使用的。所以页面实际上是 viewentry.aspx?ID=123 并且重定向会将其重定向到 /123。

我想你可能做错了?如果您使用 IIS 7 中的向导为 SEO 友好的 URL 设置 URL 重写并使用 viewentry.aspx?ID=erf4d 作为基础,它应该可以帮助您到达您需要的地方。

重定向/重写工作,因此如果您转到 test.com/123,它将起作用,但如果您转到 test.com/view.aspx?ID=123,它会将您发送到 test.com/123。我认为你追求的是哪个?

干杯

编辑:这是我使用的一个例子。它将读取 news.aspx?page=1 并重写为 news/1/。但由于规则,news/1/ 实际上也有效,因此如果需要,可以在锚点中以这种方式引用。

            <rule name="Redirect - /news.aspx?page=a to /news/a/" enabled="true" stopProcessing="true">
                <match url="^news\.aspx$" />
                <conditions logicalGrouping="MatchAll" trackAllCaptures="false">
                    <add input="{REQUEST_METHOD}" pattern="^POST$" negate="true" />
                    <add input="{QUERY_STRING}" pattern="^page=([0-9]{1,3})$" />
                </conditions>
                <action type="Redirect" url="news/{C:1}" appendQueryString="false" />
            </rule>
            <rule name="Rewrite - /news/a/ to page=a" enabled="true" stopProcessing="true">
                <match url="^news/([^/]+)/?$" />
                <conditions logicalGrouping="MatchAll" trackAllCaptures="false">
                    <add input="{REQUEST_FILENAME}" matchType="IsFile" negate="true" />
                    <add input="{REQUEST_FILENAME}" matchType="IsDirectory" negate="true" />
                </conditions>
                <action type="Rewrite" url="news.aspx?page={R:1}" />
            </rule>
于 2012-05-21T09:27:18.127 回答