How to Remove the Hosting Folder Name from MVC URL

I'm hosting several MVC websites on GoDaddy shared hosting. I noticed that the hosting folder name is being added by default to the URL. 

This is not an issue in GoDaddy shared hosting but it is a normal behavior when hosting the website in a virtual directory.

To solve this issue, add the following into your web.config’s system.webServer element:

    <rule name="Remove Virtual Directory">
      <match url=".*" />
      <action type="Rewrite" url="{R:0}" />

This causes URL rewrite to add the original URL (the one with no folder name) to a ServerVariable which is used by ASP.NET MVC to generate URLs.

No Comments

Add a Comment

As it will appear on the website

Not displayed

Your website