[英]URL Rewrite rule for IIS to replace folder path in everypage
We are having more than 300 pages in my website project. 我的网站项目中有超过300页。 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 ) 图像的当前实现(在aspx中,在css中)
http://www.mysite.com/assets/common/image1.jpg
sometimes in webpage and css it is specified like this 有时在网页和CSS中它被指定为这样
~/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
所以你可以看到所有的图像来自~/assets
文件夹但现在我想用http://static.mysite.com
创建一个替换~/assets
的规则
How can I achieve this in IIS using rewrite rule. 如何使用重写规则在IIS中实现此目的。
<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 希望有IIS规则,当找到上面的代码时,用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. 您需要在IIS中创建出站规则。 Rule will need following: 规则需要遵循:
^(.*)/assets/(.*)
模式是^(.*)/assets/(.*)
Bellow simple rule which meets above: 符合上述条件的贝娄简单规则:
You can try this 你可以试试这个
<rule name="assets redirection" stopProcessing="false">
<match url="^(.*)/(assets)/(.*)" ignoreCase="false" />
<action type="Redirect" url="{R:1}/{R:3}" />
</rule>
It will redirect whatever/assets/common/image1.jpg
to whatever/common/image1.jpg
它会将whatever/assets/common/image1.jpg
重定向到whatever/common/image1.jpg
Update: 更新:
<rule name="assets redirection" stopProcessing="false">
<match url="^(.*)/(assets)/(.*)" ignoreCase="false" />
<action type="Redirect" url="static.mysite.com/{R:3}" />
</rule>
umm some how you can do like this 嗯,你可以这样做
string imageUrl= Request.Url.Scheme + "://" + Request.Url.Authority + "/Image/logo/Logo.png";
Scheme is your web Schemes http or https etc. Authority is your web domain name with port if any. Scheme是您的网站方案http或https等。权限是您的网站域名,如果有的话。 Then here it goes your image url completely. 然后在这里它完全是你的图像网址。
I have used this logo url for the ssrs report service and got fine.Hope it ll work for you. 我已经使用这个标志网址为ssrs报告服务并且很好。希望它能为你工作。
Comments and queries are welcome . 欢迎提出意见和疑问。 Thank you. 谢谢。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.