0
votes

I'm trying to write a rewrite rule in on Windows Server 6.2. Although I used IIS Manager to create the code, it didn't work.

I tried stopProcess true/false, used different regex, restart server several times. Nothing changed. I followed the whole steps on Microsoft's web site on https://docs.microsoft.com/en-us/iis/extensions/url-rewrite-module/creating-rewrite-rules-for-the-url-rewrite-module

<system.webServer>
    <rewrite>
      <rules>
        <rule name="Rewrite to e-campus" stopProcessing="true">
          <match url="[^\/]+\/\/([^\/]+:?[0-9]?)\/.*" />
          <action type="Rewrite" url="{R:1}" />
        </rule>
      </rules>
    </rewrite>
  </system.webServer>

I want to show only main URL. My domain is http://e-campus.example.com.

For example if someone go to that link: http://e-campus.example.com/Login/Student Server should rewrite to this: e-campus.example.com (with hiding http:// but it's not important)

So basically I just want to show main URL. But it keeps showing full path. What am I missing here?

1

1 Answers

0
votes

According to your description, I found your regex match the whole url. But the iis url rewrite will not get the whole domain, it will just get the part of the url not the whole url.

For example:

If your url is http://e-campus.example.com/Login/Student., the match url part is login/Student.

So if you want to rewrithe all the request to e-campus.example.com, you should use below url rewrite rule.

<system.webServer>
    <rewrite>
      <rules>
        <rule name="Rewrite to e-campus" stopProcessing="true">
          <match url="(.*)" />
          <action type="Rewrite" url="http://e-campus.example.com/" />
        </rule>
      </rules>
    </rewrite>
  </system.webServer>