1
votes

I need to create easy to remember URL's that redirect to long and hard to remember paths for a large number of applications.

i.e. subdomain.domain.edu/shortname redirects to https://www.subdomain.domain.edu/mainApplication/subfolder/page

I'm using the URL Rewrite module in IIS 8.5, but I keep getting a 404 when I browse to the short alias. I know the rewrite module is working as I use it to handle rewriting HTTP to HTTPS and to add WWW to a URL.

My rewrite rule looks like:

    <rewrite>
        <rules>
            <rule name="Easy to remember shortcut" stopProcessing="true">
                <match url=".*subdomain.domain.edu/shortname" />
                <conditions>
                    <add input="{URL}" pattern=".*/shortname" />
                </conditions>
                <action type="Redirect" url="https://www.subdomain.domain.edu/mainApplication/subfolder/page.aspx" />
            </rule>
        </rules>
    </rewrite>

Of course this returns a 404. Any ideas?

Forgive me if there is already an answer to this in another post, however, I've read through and tried over 30 posts on the URL rewrite module and have not yet found the solution for actually creating an alias.

1
Please check my answer and let me know if I missed something - Ravi A.

1 Answers

1
votes

Url rewrite match condition won't be able to see your domain i.e. if the URL is https://www.subdomain.domain.edu/shortname the match part can only see shortname (anything after domainname/).

To validate the host we need to add in the conditions clause. So your rule will be something like below

<rule name="shortnameURL" enabled="true" stopProcessing="true">
    <match url="shortname" />
    <action type="Redirect" url="mainApplication/subfolder/page" />
    <conditions>
        <add input="{HTTP_HOST}" pattern=".*subdomain.domain.edu" />
    </conditions>
</rule>

Also it should be ok if you add the entire URL here

<action type="Redirect" url="mainApplication/subfolder/page" /> as below

<action type="Redirect" url="https://www.subdomain.domain.edu/mainApplication/subfolder/page" />