Sign in to follow this  

Proper way to handle a redirect?

Recommended Posts

CheckOne    1

Hi I have 4 domains that are all similar and I want to redirect them to one. I created an Active Server Document and wrote something like this:

<script runat="server" Language="c#">

public void Page_Init(Object Src, EventArgs E)

{

switch((Request.ServerVariables["HTTP_HOST"]).Replace("www.",""))

{

case "site-1.com":

Response.Redirect("http://mainsite.com");

break;

case "site2.net":

Response.Redirect("http://mainsite.com");

break;

case "site2inc.com":

Response.Redirect("http://mainsite.com");

break;

default:

Response.Redirect("");

break;

}

}

</script>

But the original domain is still showing in the URL bar. So if I type www.site-1.com it shows as www.site-1.com, not mainsite.com. So I am assuming that the redirect is not working. So I was wondering if I did something wrong here or how I should be doing this?

Thanks for the help. I appreciate it. :)

Also, I now change the path for the other sites to the root and get a Server error... So I'm assuming that wasn't right. I don't know how else to direct this to the Active Scrit file. Edit * Actually that only happens if I type the www.?

Share this post


Link to post
Share on other sites
primexx    372

google http 301 or 302 redirects

Share this post


Link to post
Share on other sites
simsie    4

What's your web server software?

I'm going to assume IIS. For this I did it by creating 5 different sites in the same pool and then on each one there should be a way to configure a redirect in the GUI.

As for the typing www or not if you right click on each site in IIS and go to 'bindings' I think it is you can add extra domain names. I had to manually add the www on mine as well as the non-www version.

Share this post


Link to post
Share on other sites
Seahorsepip    561

use a .htacces file to redirect, it's the fastest and best way in my opinion.

Share this post


Link to post
Share on other sites
Sandor    436

use a .htacces file to redirect, it's the fastest and best way in my opinion.

web.config might be more appropriate if it's an IIS based system...

Share this post


Link to post
Share on other sites
Seahorsepip    561

web.config might be more appropriate if it's an IIS based system...

I didn't knew it was a ISS based system :p

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this  

  • Recently Browsing   0 members

    No registered users viewing this page.