IIS的URL重写规则,以取代在everypage文件夹路径 [英] URL Rewrite rule for IIS to replace folder path in everypage
问题描述
我们遇到在我的网站项目300多页。在时间,我们已经创建了一个新的服务器,是安全的。此服务器是专门用于网站的所有图像。
因此,这里的情景:
-
当前实现图像(ASPX,在CSS)
http://www.mysite.com/assets/common/image1.jpg
-
有时网页和CSS是这样规定的。
〜/资产/普通/ image1.jpg
-
想用somethig这样。
http://www.static.mysite.com/common/image1.jpg
-
和安全网页
https://www.static.mysite.com/common/image1.jpg
因此,大家可以看到所有的图像是从〜/资产
文件夹中来,但现在我想建立一个规则替换〜/资产
与 http://static.mysite.com
我如何使用IIS重写规则实现这一目标。
例子:
ASPX
< IMG SRC =/资产/普通/ image1.jpgID =ImageId1ALT =图像WIDTH =100HEIGHT =100/>< IMG SRC =http://mysite.com/assets/common/image2.jpgID =ImageId2ALT =图像WIDTH =100HEIGHT =100/>
想有IIS规则,当高于code发现,与 HTTP替换: //static.mysite.com/common/image1.jpg
< IMG SRC =http://static.mysite.com/common/image1.jpgID =ImageId1ALT =图片WIDTH =100HEIGHT =100/>
< IMG SRC =http://static.mysite.com/common/image2.jpgID =ImageId2ALT =图像WIDTH =100HEIGHT =100/>
您需要在IIS中创建出站规则。规则将需要以下内容:
- precondition应该只检查HTML文件(我用默认IsHTML)
- 在匹配的内容中选择元素,你想查询的链接
- 模式是
^(。*)/资产/(.*)
- Action属性是 http://static.mysite.com/ {R:2}。 R:2 reffers第二()在上述正则前pression。你可以检查你测试模式按钮,点击后需要什么。
娄简单的规则,符合以上:
We are having more than 300 pages in my website project. Over the time we have created a new server which is secure. This server is specially used for all the images in website.
So here is the scenario:
current implementation for images ( in aspx, in css )
http://www.mysite.com/assets/common/image1.jpg
sometimes in webpage and css it is specified like this
~/assets/common/image1.jpg
would like to use somethig like this.
http://www.static.mysite.com/common/image1.jpg
and for secure pages
https://www.static.mysite.com/common/image1.jpg
So as you can see all the images are coming from ~/assets
folder BUT now I want to create a rule replacing ~/assets
with http://static.mysite.com
How can I achieve this in IIS using rewrite rule.
EXAMPLE:
ASPX
<img src="/assets/common/image1.jpg" id="ImageId1" alt="Image" width="100" height="100" />
<img src="http://mysite.com/assets/common/image2.jpg" id="ImageId2" alt="Image" width="100" height="100" />
Would like to have IIS rule, when finds above code, replace it with http://static.mysite.com/common/image1.jpg
<img src="http://static.mysite.com/common/image1.jpg" id="ImageId1" alt="Image" width="100" height="100" />
<img src="http://static.mysite.com/common/image2.jpg" id="ImageId2" alt="Image" width="100" height="100" />
You need to create Outbound Rule in IIS. Rule will need following:
- Precondition should only check html files (I used default IsHTML)
- In "Matching the content with" choose elements in which you would like to check links
- Pattern is
^(.*)/assets/(.*)
- Action properties is http://static.mysite.com/{R:2}. R:2 reffers to second () in above regular expression. You could check what you need after click of "Test pattern" button.
Bellow simple rule which meets above:
这篇关于IIS的URL重写规则,以取代在everypage文件夹路径的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!