Showing posts with label URL Rewrite. Show all posts
Showing posts with label URL Rewrite. Show all posts

Saturday, March 1, 2008

URL Rewriting and Google Website Optimizer

I've begun discovering the power of URL rewriting. As our KaDonk website is growing furiously, URL rewriting is the only good method of fixing old pages that have been removed.

This becomes particularly true after having run several Google Website Optimizer tests. The Google website optimizer are great, but when using A/B pages, let's say on registration.aspx, you inevitably end up with registration1.aspx, registration2.aspx, etc... These pages are just temporary for using while the experiments are running.

Once the experiment ends though, users may have links to these pages, and search engines may have indexed them.

So I installed a freeware URL rewriter, and now all I have to do is redirect the temporary pages to the main one after each experiment. Simple, and clean.

Another benefit I recently discovered was when we added our entire library of help files to our website. These are the same pages that are included in our F1 Help inside LiveProject. Internally, they all reference eacher using *.htm links. But our pages are in ASP.NET, so references would basicallyshow the raw files instead of my encapsulator .aspx files.

URL rewriting to the rescue. Each reference to a .htm file is automatically redirected to an .aspx file of the correct name. Literally with one line of configuration all the links in our embedded help files works.

It looks something like this:



May I add this is insanely cool !!

Saturday, January 26, 2008

Redirecting domain.com to www.domain.com through global.asax

OK this was a tricky one to solve, redirecting kadonk.com to www.kadonk.com using ASP.NET in C#. The solution came from lots of browsing, and many sources, and looks like this in global.asax (replace 'domain' with your own domain of course):


void Application_BeginRequest(object sender, EventArgs e)
{

// Don't do nothing while in test mode !
if (!Request.Url.Host.Equals("localhost")
&& !Request.Url.Host.ToString().Contains("www.domain.com")
&& Request.Url.Host.ToString().Contains("domain.com"))
{
string Result = string.Concat(
"http://",
Request.Url.Authority.Replace("domain.com", "www.domain.com"),
HttpContext.Current.Response.ApplyAppPathModifier(Request.Path),
Request.Url.Query);

HttpContext.Current.Response.Redirect(Result, true);
}
}




This will redirect kadonk.com to www.kadonk.com, but not any other domains we have, and it won't touch localhost (which may be funky). It will preserve Session variables and query strings, and should generally be nice and safe. You will note that I hardcoded "http://". I will fix that later to retain the protocol, but in any case I am using Matt Sollars GREAT WebpageSecurity package for SSL redirects!