homepage Welcome to WebmasterWorld Guest from 54.242.231.109
register, free tools, login, search, pro membership, help, library, announcements, recent posts, open posts,
Become a Pro Member
Home / Forums Index / Microsoft / Microsoft IIS Web Server and ASP.NET
Forum Library, Charter, Moderators: ocean10000

Microsoft IIS Web Server and ASP.NET Forum

    
How to do asp 301 conditional redirect subdomain
hairresources




msg:4478545
 9:19 pm on Jul 24, 2012 (gmt 0)

I have a directory set up in the root of my main site (IIS Web Server, site in asp) that is a subdomain for the main site. My question is how do I set up a conditional 301 redirect in asp so that when people type in sub.mainsite.com it automatically goes to this directory and shows the whole subdomain site.

I tried this at the top of the default.asp page for the main site:

<%
if Request.ServerVariables("SERVER_NAME") = "sub.example.com" then
Call Response.Redirect("http://sub.example.com/subdirectoryname/")
end if
%>

It redirects to the subdomain, but if you click on any link on the subdomain website it says 404 not found.

Any help would be greatly appreciated!

[edited by: Ocean10000 at 3:50 pm (utc) on Jul 25, 2012]
[edit reason] examplefied [/edit]

 

g1smd




msg:4478562
 10:49 pm on Jul 24, 2012 (gmt 0)

What do you mean by "goes to"?

It's one of the most abused phrases quoted in questions here with (at least) three different meanings depending on what you actually want to do.

hairresources




msg:4478603
 12:53 am on Jul 25, 2012 (gmt 0)

By 'goes to' I mean that any request for the sub.example.com is directed to the subdomain website files that are located in a separate directory from the main site.

A request for a subdomain shows the subdomain website.

[edited by: Ocean10000 at 3:50 pm (utc) on Jul 25, 2012]
[edit reason] examplefied [/edit]

freitasm




msg:4478605
 1:01 am on Jul 25, 2012 (gmt 0)

Open IIS Manager, create a new site correctly configured for the subdomain in question.

Then on the main site, click on the folder and configure the HTTP Redirect to the new subdomain.

You might want to use http://sub.example.com$S$Q in the "Redirect requests to this destination" so that ALL requests are passed including query strings.

[edited by: Ocean10000 at 3:49 pm (utc) on Jul 25, 2012]
[edit reason] broke hyperlink/examplefied [/edit]

johnnymward




msg:4497290
 9:33 am on Sep 19, 2012 (gmt 0)

To implement a conditional 301 redirect in ASP, two elements must be present at the top of the default document an if statement testing the incoming HTTP header and the 301 redirect then a conditional redirect is useful when subdomains must redirect to the content of a subfolder other than the document root
Here is the example coding
private void Page_Load(object sender, System.EventArgs e)
{
If (Request.ServerVariables["SERVER_NAME"] == "sub.domain.com") then
Response.Status = "301 Moved Permanently";
Response.AddHeader("Location","http://sub.domain.com/other_content/index.html");
end if
}

freitasm




msg:4497486
 7:40 pm on Sep 19, 2012 (gmt 0)

You should have response.end before the end if, as the header will be added by the entire script will be processed before actually sending it to the browser.

bhaveshvsmart




msg:4517037
 7:38 am on Nov 8, 2012 (gmt 0)

Thank you give me a information to 301 redirect sub domain.

Global Options:
 top home search open messages active posts  
 

Home / Forums Index / Microsoft / Microsoft IIS Web Server and ASP.NET
rss feed

All trademarks and copyrights held by respective owners. Member comments are owned by the poster.
Home ¦ Free Tools ¦ Terms of Service ¦ Privacy Policy ¦ Report Problem ¦ About ¦ Library ¦ Newsletter
WebmasterWorld is a Developer Shed Community owned by Jim Boykin.
© Webmaster World 1996-2014 all rights reserved