Iis 7 IIS URL重写-友好URL:Querystring变量重复
在IIS 7配置中,我创建了友好的URL进行转换:Iis 7 IIS URL重写-友好URL:Querystring变量重复,iis-7,url-rewriting,Iis 7,Url Rewriting,在IIS 7配置中,我创建了友好的URL进行转换: http://mysite/restaurant.aspx?Name=SomeName 到 为此,我有以下规则: <rule name="RedirectUserFriendlyURL1" enabled="true" stopProcessing="true"> <match url="^Restaurant\.aspx$" /> <conditions> <add inp
http://mysite/restaurant.aspx?Name=SomeName
到
为此,我有以下规则:
<rule name="RedirectUserFriendlyURL1" enabled="true" stopProcessing="true">
<match url="^Restaurant\.aspx$" />
<conditions>
<add input="{REQUEST_METHOD}" pattern="^POST$" negate="true" />
<add input="{QUERY_STRING}" pattern="^Name=([^=&]+)$" />
</conditions>
<action type="Redirect" url="{C:1}" appendQueryString="false" />
</rule>
<rule name="RewriteUserFriendlyURL1" enabled="true" stopProcessing="false">
<match url="^([^/]+)/?$" />
<conditions>
<add input="{REQUEST_FILENAME}" matchType="IsFile" negate="true" />
<add input="{REQUEST_FILENAME}" matchType="IsDirectory" negate="true" />
<add input="{REQUEST_FILENAME}" pattern=".aspx" negate="true" />
</conditions>
<action type="Rewrite" url="Restaurant.aspx?Name={R:1}" appendQueryString="false" />
</rule>
请注意,我已将appendQueryString设置为false。表单回发操作使用基础url,而不是原始url
一个简单的解决方案(我相信服务器端表单操作属性仅在3.5+中可用):
<rule name="RedirectUserFriendlyURL1" enabled="true" stopProcessing="true">
<match url="^Restaurant\.aspx$" />
<conditions>
<add input="{REQUEST_METHOD}" pattern="^POST$" negate="true" />
<add input="{QUERY_STRING}" pattern="^Name=([^=&]+)$" />
</conditions>
<action type="Redirect" url="{C:1}" appendQueryString="false" />
</rule>
<rule name="RewriteUserFriendlyURL1" enabled="true" stopProcessing="false">
<match url="^([^/]+)/?$" />
<conditions>
<add input="{REQUEST_FILENAME}" matchType="IsFile" negate="true" />
<add input="{REQUEST_FILENAME}" matchType="IsDirectory" negate="true" />
<add input="{REQUEST_FILENAME}" pattern=".aspx" negate="true" />
</conditions>
<action type="Rewrite" url="Restaurant.aspx?Name={R:1}" appendQueryString="false" />
</rule>
protected void Page_Load(object sender, EventArgs e)
{
if ( !String.IsNullOrEmpty(Request.ServerVariables["HTTP_X_ORIGINAL_URL"]) )
{
form1.Action = Request.ServerVariables["HTTP_X_ORIGINAL_URL"];
}
}