Url rewriting Web.config URL重写特定的匹配URL
我有以下web.config URL重写规则:Url rewriting Web.config URL重写特定的匹配URL,url-rewriting,web-config,Url Rewriting,Web Config,我有以下web.config URL重写规则: <rule name="RedirectUserFriendlyURL1" stopProcessing="true"> <match url="^propertysearch\.asp$" /> <conditions> <add input="{REQUEST_METHOD}" pattern="^POST$" negate="true" /> &l
<rule name="RedirectUserFriendlyURL1" stopProcessing="true">
<match url="^propertysearch\.asp$" />
<conditions>
<add input="{REQUEST_METHOD}" pattern="^POST$" negate="true" />
<add input="{QUERY_STRING}" pattern="^urlrewrite=([^=&]+)$" />
</conditions>
<action type="Redirect" url="{C:1}" appendQueryString="false" />
</rule>
<rule name="RewriteUserFriendlyURL1" stopProcessing="true">
<match url="^([^/]+)/?$" />
<conditions>
<add input="{REQUEST_FILENAME}" matchType="IsFile" negate="true" />
<add input="{REQUEST_FILENAME}" matchType="IsDirectory" negate="true" />
</conditions>
<action type="Rewrite" url="propertysearch.asp?urlrewrite={R:1}" />
</rule>
问题是它将此应用于所有内容,所以我要做的是更改匹配url语法,使其仅在url中包含“-to rent in-”时运行,因此
www.domain.com/villas-to-rent-in-florida
将符合条件并应用规则,但这不会
www.domain.com/testentry
我尝试了不同的变体,但它不断出现错误:(要获取url以触发重写,仅当
-租入-
是url的第一部分时,您可以使用:
<rule name="RewriteUserFriendlyURL1" stopProcessing="true">
<match url="^(.+-to-rent-in-.+)/?$" />
<conditions>
<add input="{REQUEST_FILENAME}" matchType="IsFile" negate="true" />
<add input="{REQUEST_FILENAME}" matchType="IsDirectory" negate="true" />
</conditions>
<action type="Rewrite" url="propertysearch.asp?urlrewrite={R:1}" />
</rule>
url=“^(+-to rent in-.+)/?$”
将匹配任何url,该url在-to rent in-
之前至少包含一个字符,之后至少包含一个字符
您不希望将前面或后面的字符限制为字母数字,因为您的url可能类似于:
www.domain.com/apartments to rent in new york
(其中new york
包含-
)可以-租入-
在url中的任何位置,或者只在第一个/
之前吗?谢谢你回来。只在第一个/。基本上url的外观总是这样:www.domain.com/[property type]-租入-[location]所以www.domain.com/villas-to-rent-in-florida,www.domain.com/repartments-to-rent-in-new-york,等等。希望有帮助:)我无法测试我在周一之前发布的答案,所以如果它不起作用,请毫不犹豫地发表评论!大家好,非常感谢:)。遗憾的是,它不太管用,当我访问一个url时,它会提供一个在mo中找不到的页面。。。很抱歉,真的很感谢你的帮助。这很好,谢谢你为我这么做。非常感谢:)