Solved

Response Redirect https//domain.com to https://secure.domain.com

Posted on 2013-01-22
6
514 Views
Last Modified: 2013-02-04
My website is built in asp.net 2.0 and C#. my main website is www.domain.com and my secured checkout process is under secure.domain.name

I noticed today that google was indexing some of my products under https://domain.com/prodcuts.aspx?catid=2&prodid=19 instead of https://secure.domain.com/prodcuts.aspx?catid=2&prodid=19. mostly due to relative linking by the developer.

IS there anyway I can rediect the above url to either https://secure.domain.com/products.aspx?catid=2&prodid=19.

and in general anything that starts with https://domain.com to https://secure.domian.com

basically I need to append secure infront of domain.com

any advice or example is highly appreciated

Thanks
0
Comment
Question by:niceoneishere
6 Comments
 
LVL 20

Expert Comment

by:informaniac
ID: 38808542
0
 
LVL 16

Assisted Solution

by:Rose Babu
Rose Babu earned 500 total points
ID: 38808803
Hi,

if you have a master page or a common header control then use the below code in that

protected void Page_Init(object sender, EventArgs e)
{
	HttpContext context = HttpContext.Current;
	string redirectUrl = null;

	try
	{
		// https://domain.com will be replaced with https://secure.domian.com
		if (context.Request.Url.ToString().StartsWith("") == true)
		{
			redirectUrl = context.Request.Url.ToString().Replace("https://domain.com", "https://secure.domian.com");
		}

		if (redirectUrl != null)
		{
			context.Response.Redirect(redirectUrl);
		}
	}
	catch (Exception ex)
	{
		context.Response.Redirect(redirectUrl, false);
	}
}

Open in new window

This code will redirect all your https://domain.com to https://secure.domian.com

or you may use the same code in the necessary pages alone like abc.aspx, etc...

Try this... Hope this will help you a lot.
0
 
LVL 16

Expert Comment

by:Kamal Khaleefa
ID: 38809050
use URL Rewrite module in the IIS itself
0
DevOps Toolchain Recommendations

Read this Gartner Research Note and discover how your IT organization can automate and optimize DevOps processes using a toolchain architecture.

 
LVL 1

Author Comment

by:niceoneishere
ID: 38809878
Thanks  srosebabu, what am i supposed to put under StartsWith().

Appreciate it
0
 
LVL 16

Accepted Solution

by:
Rose Babu earned 500 total points
ID: 38813189
Oh.. My Mistake... ;-)

Update like this...

if (context.Request.Url.ToString().StartsWith("https://domain.com") == true)
0
 
LVL 1

Author Closing Comment

by:niceoneishere
ID: 38851383
Thanks
0

Featured Post

DevOps Toolchain Recommendations

Read this Gartner Research Note and discover how your IT organization can automate and optimize DevOps processes using a toolchain architecture.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Authentication of Web Services 3 46
Syntax error 9 45
Error in script 11 43
SQL Exceptions 3 35
Wouldn’t it be nice if you could test whether an element is contained in an array by using a Contains method just like the one available on List objects? Wouldn’t it be good if you could write code like this? (CODE) In .NET 3.5, this is possible…
Calculating holidays and working days is a function that is often needed yet it is not one found within the Framework. This article presents one approach to building a working-day calculator for use in .NET.
You have products, that come in variants and want to set different prices for them? Watch this micro tutorial that describes how to configure prices for Magento super attributes. Assigning simple products to configurable: We assigned simple products…
This is a video describing the growing solar energy use in Utah. This is a topic that greatly interests me and so I decided to produce a video about it.

932 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

11 Experts available now in Live!

Get 1:1 Help Now