Duplicate domain in URL or domain / AppName

I am sure this is a simple problem, but I noticed that when I host a (shared host on GoDaddy) website, the URL repeats the name of the application.

For example, I have http://makedifferences.org , if I go for it, that’s fine, but if I click on the link, it will lead me to http://makedifferences.org/makedifferences/ ...

This is not only this site, all of my sites are on GoDaddy, and I think that it may be the same on my sites hosted elsewhere, but I can not check them now.

I do not use web deployment to deploy it because, as I thought, it had to run IIS. I assume that this should be a parameter in the publication settings, but I played with them and could not get it to leave.

Any advice would be appreciated. Thanks, Garrett

Update

This is apparently not the mvc thing, as I am checking the site that I posted on dotnet-host.com and it does not have this problem. So I think this is something with my settings in Godaddy.

I deleted the folder and installed the virtual folder, and this did not fix the problem.

I have several hosting sites through them, and my domain name A is my dedicated IP address for all sites, and then in host management. I indicate the domain name in the folder in which the site is located.

I think this is the right way to do this, but I'm not sure.

Repeat my problem now that I know a little more about it , if I type the http://makedifferences.org/Charities/Details/3 page loads, and everything is perfect. But if I click on the link on the main page to go there, then the address is http://makedifferences.org/makedifferences/Charities/Details/3

Thanks, why I thought it was a parameter in Visual Studio.

+4
source share
2 answers

There are two things that cause this behavior.

  • Your application is installed in a folder instead of the root directory for shared hosting.
  • DNS settings indicate the domain name in this folder.

I assume that you host several websites on shared hosting.

To get rid of this problem, you need to go to IIS settings and set these folders as virtual directories ..... Or create them for each website .... And then install the application in this folder.

UPDATE

This is actually not a problem with GoDaddy's shared hosting, but a problem with placing an ASP.NET MVC site in a virtual directory. When you use the shared hosting provided by GoDaddy, you get the root folder and unlimited subfolders, each of which can be its own domain, through a virtual directory. Unfortunately, the MVC routing mechanism creates URLs that will include the virtual directory name appended to the domain name.

For example, let's say you have a domain named http://www.example.com , and your folder / virtual directory name is / File. If you take the MVC template project without any changes and upload it to your folder, and then go to your URL, everything will look fine. You will see the Home and About tabs in the upper right corner of the page. When you click on the "About" tab, as it is redirected to the main controllers. About the action, you rightly expect the URL to be www.example.com/Home/About. However, you will see that the URL generated by the ActionLink method includes the name of the virtual directory. Therefore, the URL will be: www.example.com/File/Home/About.

To get rid of this problem, add the following code to your Web.configs system.webServer element

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

The solution requested HERE

Good luck: -)

+5
source

To work in all cases, I used the rewrite rule:

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

And the function below:

 protected void Application_BeginRequest() { #region Godaddy shared host fix - Detect VDIR in url and remove //verified that HTTP_X_ORIGINAL_URL keeps the original url (withoud domain) before url rewrite module, //that way can check if the virtual directory name is at start, and remove it. if (Request.ServerVariables.AllKeys.Contains("HTTP_X_ORIGINAL_URL")) { var origUrl = Request.ServerVariables["HTTP_X_ORIGINAL_URL"]; var matchVdir = "/" + Myproj.Core.Constants.Environment.HostingVirtualDirectoryName + "/"; if (origUrl.StartsWith(matchVdir)) { var urlFix = Request.Url.GetLeftPart(UriPartial.Authority) + "/" + origUrl.Remove(0, matchVdir.Length); Response.RedirectPermanent(urlFix); } } #endregion } 
+1
source

Source: https://habr.com/ru/post/1392304/


All Articles