URL Rewrite rule for IIS to replace folder path in everypage

后端 未结 3 420
死守一世寂寞
死守一世寂寞 2021-02-04 13:08

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.

相关标签:
3条回答
  • 2021-02-04 13:12

    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. 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.

    Comments and queries are welcome . Thank you.

    0 讨论(0)
  • 2021-02-04 13:14

    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

    Update:

    <rule name="assets redirection" stopProcessing="false">
        <match url="^(.*)/(assets)/(.*)" ignoreCase="false" />
        <action type="Redirect" url="static.mysite.com/{R:3}" />
    </rule>
    
    0 讨论(0)
  • 2021-02-04 13:31

    You need to create Outbound Rule in IIS. Rule will need following:

    1. Precondition should only check html files (I used default IsHTML)
    2. In "Matching the content with" choose elements in which you would like to check links
    3. Pattern is ^(.*)/assets/(.*)
    4. 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:

    enter image description here

    0 讨论(0)
提交回复
热议问题