URL Rewrite for Host Header is not working using I

2020-05-07 00:09发布

问题:

I do not want to redirect any malicious link or user to redirect to other domain. Instead it should redirect to the domain which I mentioned. So for that, I have written below Rewrite URL rule by using IIS server

<rewrite>
  <rules>
    <clear />
    <rule name="Redirect to https" stopProcessing="true">
      <match url=".*" />
      <conditions>
                    <add input="{HTTPS}" pattern="off" />
                    <add input="{HTTP_HOST}" matchType="Pattern" pattern="^([a-zA-Z0-9-_]+.)https://nvmbd1bkh150v02.rjil.ril.com$" ignoreCase="true" negate="true" />
      </conditions>
      <action type="Redirect" url="https://nvmbd1bkh150v02.rjil.ril.com/FiberInventoryPortal" redirectType="Permanent" appendQueryString="false" />
    </rule>

  </rules>
</rewrite>

But what happening here is, all my application CSS gets disturbed. Please suggest what should I do in this case.

回答1:

Not sure what you mean with "malicious" links but my guess is that you want visitors to use just that specific host name. And also that every URL should always start with /FiberInventoryPortal/.

So possibly this is what you want:

<rewrite>
    <rules>
        <clear />
        <rule name="Force HTTPS" stopProcessing="true">
            <match url="(.*)" />
            <conditions logicalGrouping="MatchAll">
                <add input="{HTTPS}" negate="true" pattern="^ON$" />
                <add input="{HTTP_HOST}" negate="true" pattern="^nvmbd1bkh150v02\.rjil\.ril\.com$" />
            </conditions>
            <action type="Redirect" url="https://nvmbd1bkh150v02.rjil.ril.com{REQUEST_URI}" redirectType="Permanent" appendQueryString="false" />
        </rule>
        <rule name="Redirect to FiberInventoryPortal" stopProcessing="true">
            <match url=".*" />
            <conditions>
                <add input="{REQUEST_URI}" matchType="Pattern" pattern="^/FiberInventoryPortal/" ignoreCase="true" negate="true" />
            </conditions>
            <action type="Redirect" url="https://nvmbd1bkh150v02.rjil.ril.com/FiberInventoryPortal/{R:0}" redirectType="Permanent" appendQueryString="false" />
        </rule>
    </rules>
</rewrite>


回答2:

According to your url rewrite codes, I found you will redirect all the request to the https://nvmbd1bkh150v02.rjil.ril.com/FiberInventoryPortal include the CSS file. This is the reason why your CSS file not working.

If your css file is also in the new site's FiberInventoryPortal folder. I suggest you could try below url rewrite rule.

<rewrite>
  <rules>
    <clear />
    <rule name="Redirect to https" stopProcessing="true">
      <match url=".*" />
      <conditions>
                    <add input="{HTTPS}" pattern="off" />
                    <add input="{HTTP_HOST}" matchType="Pattern" pattern="^([a-zA-Z0-9-_]+.)https://nvmbd1bkh150v02.rjil.ril.com$" ignoreCase="true" negate="true" />
      </conditions>
      <action type="Redirect" url="https://nvmbd1bkh150v02.rjil.ril.com/FiberInventoryPortal/{R:0}" redirectType="Permanent" appendQueryString="false" />
    </rule>

  </rules>
</rewrite>