URL重写模式匹配 - 1个规则,多个请求

时间:2014-05-12 19:36:11

标签: url url-rewrite-module

是否可以为与模式匹配的整组相关网址设置一个网址重写规则?我尝试在我的Web配置文件中创建一个URL重写规则,该规则采用特定的匹配模式,然后重定向整个URL,但只更改匹配的URL的特定部分。例如,1个URL重写规则可以实现此目的:

http://www.something.com/local-pages/my-site

http://www.something.com/local-pages/my-site/page-one

http://www.something.com/local-pages/my-site/page-two

http://www.something.com/local-pages/my-site/page-three

对于这些请求中的每一个,重定向整个内容,只更改匹配的段" my-site"到#34;你的网站?"

http://www.something.com/local-pages/your-site

http://www.something.com/local-pages/your-site/page-one

http://www.something.com/local-pages/your-site/page-two

http://www.something.com/local-pages/your-site/page-three

2 个答案:

答案 0 :(得分:1)

这就是我想要的:

<rule name="myRule" stopProcessing="true">
<match url="local-pages/my-site/(.*)" />
<action type="Redirect" url="local-pages/your-site/{R:1}" redirectType="Permanent" />

答案 1 :(得分:0)

是的,规则看起来像这样:

RewriteEngine On
RewriteRule /local\-pages/my\-site(.*)$ /local-pages/your-site$1 [R=301,L,QSA,NC]