How to redirect sub.domain.com to proper url
I have a website and some sub-domains which are working like so:
http://sub.domain.com/ goes to: http://www.domain.com/sub/.
But what I want it do do is:
http://sub.domain.com/ goes to: http://sub.domain.com/sub/ but still keep
the URI in the address bar the same, so it should read:
http://sub.domain.com/.
So when a user enters http://sub.domain.com/ in the address bar, it will
display content from http://sub.domain.com/sub/ but still display
http://sub.domain.com/ in the address bar.
If the user visits another page in sub.domain.com website the address bar
should still display correct address which might be something like
http://sub.domain.com/page2.html instead of
http://domain.com/sub/page2.html.
How can we achieve this? I've done it years ago but to be honest I don't
remember the approach I used and I have tried a few articles online but
they weren't correct.
Any help is greatly appreciated
Thank you
My current code is:
@{
// Redirect from subdomain if necessary.
string variables = (Request.ServerVariables["SERVER_NAME"]);
switch(variables.Trim().ToLower())
{
case "sub.domain.com":
Response.Redirect("http://domain.com/sub/", true);
break;
default:
Layout = "~/Shared/_View.cshtml";
break;
}
}
No comments:
Post a Comment