Welcome to WebmasterWorld Guest from 35.173.57.202

Forum Moderators: ocean10000

Message Too Old, No Replies

Redirecting apache query strings in IIS

Have been told only way to do it is through a 302 redirect

     
1:36 am on Apr 28, 2010 (gmt 0)

New User

10+ Year Member

joined:Feb 25, 2009
posts: 19
votes: 0


We have recently had our website redesigned by a company that uses IIS7 infrastructure. I don't have much experience with IIS so sorry if I have missed out some information.

Our previous site was using Apache and the product pages had URLs like:
/cat/index.cgi/shopfront/view_product_details?category_id=123&product_id=123

The company has setup 302 redirects for anything that has /cat/ and points the browser to the home page.

They have said that this is the only way to do it - you can't do a page to page 301 redirect in IIS7 with that kind of query string, you can only send those requests to a single page, and that it can only be a 302 redirect.

Is this true or is there some kind of work around - the old structure was around for a while and has good history in Google which I am keen to pass on to the new pages (or at least the home page)

There have been 301 redirects implemented for our old static pages, it has just been highlighted that the dynamic pages is where the issues are.
8:49 am on Apr 28, 2010 (gmt 0)

Senior Member

WebmasterWorld Senior Member 10+ Year Member

joined:Feb 1, 2005
posts:733
votes: 0


They have said that this is the only way to do it - you can't do a page to page 301 redirect in IIS7 with that kind of query string, you can only send those requests to a single page, and that it can only be a 302 redirect.

That is not correct, it's quite easy to do with IIS7 and the IIS Rewrite Module [learn.iis.net]. You can even import existing mod_rewrite rules if you already have them.
12:04 pm on Apr 28, 2010 (gmt 0)

Senior Member

WebmasterWorld Senior Member 10+ Year Member

joined:Feb 1, 2005
posts: 733
votes: 0


I had some free time in my lunch break so I decided to write the rule for you:
<rule name="Legacy Category Product Redirect">
<match url="^cat/index\.cgi/shopfront/view_product_details$" />
<conditions>
<add input="{QUERY_STRING}" pattern="^category_id=([0-9]+)&amp;product_id=([0-9]+)$" />
</conditions>
<action type="Redirect" url="default.aspx?cat={C:1}&amp;prod={C:2}" appendQueryString="false" />
</rule>


This will 301 redirect:
http://www.example.com/cat/index.cgi/shopfront/view_product_details?category_id=123&product_id=123
to:
http://www.example.com/default.aspx?cat=123&prod=123

Just changed the url value in action type="Redirect" to your desired url.
11:22 pm on Apr 28, 2010 (gmt 0)

New User

10+ Year Member

joined:Feb 25, 2009
posts:19
votes: 0


Wow Marcel, That is fantastic. I have sent on to the design company - I will let you know their response.
1:49 am on Apr 29, 2010 (gmt 0)

New User

10+ Year Member

joined:Feb 25, 2009
posts:19
votes: 0


The design company has come back and stated that they are unable to implement a rewrite module as the site is hosted on a server with thousands of other sites (in a cloud environment), so doing slow would create processing overheads.

They did this as a site wide URL redirect in code (not IIS) as a 302 Response.Redirect. They couldn’t do it as a 301 redirect as "that is performed in IIS, but IIS cannot do redirects if there is a querystring (IE: ‘?’ character)" given that they don't use the rewrite module.

Does it make sense that only 302 redirects are possible given their situation of not being able to use the rewrite module?
4:40 am on Apr 29, 2010 (gmt 0)

Senior Member

WebmasterWorld Senior Member 10+ Year Member

joined:Feb 1, 2005
posts:733
votes: 0


The design company has come back and stated that they are unable to implement a rewrite module ... doing so would create processing overheads.

Really? And checking *every single* request to see if it contains the string '/cat/' doesn't?

To be perfectly honest, I would consider moving the website to another company. They really do not seem to know what they are talking about.

Here is another option that will work without installing the rewrite module.

- First create the directory structure of:
/cat/index.cgi/shopfront/view_product_details/

- Then create a default.aspx within the view_product_details folder and add the following code:
protected void Page_Load(object sender, EventArgs e)
{
string cat = Request.QueryString.Get("category_id");
string prod = Request.QueryString.Get("product_id");

Response.Status = "301 Moved Permanently";
Response.AddHeader("Location", String.Format("http://www.example.com/default.aspx?cat={0}&prod={1}", cat, prod));
}

This works fairly well (although it seems to 301 redirect twice due to the missing / at the end), but it's still better than a 302 redirect.

It will also have the added benefit of lowering overhead on the server. Instead of checking every single incoming request for the '/cat/' string, this will only fire when necessary.

* Added: If they are using .NET 4.0 they can also use Response.RedirectPermanent() to replace the last two lines. Routing is also a possibility, but I've no experience with that.
12:24 am on Apr 30, 2010 (gmt 0)

New User

10+ Year Member

joined:Feb 25, 2009
posts:19
votes: 0


Thanks again - I sent it on to the designers and they say in can be implemented that way - for a cost of course :)

Unfortunately we are tied to them as they have their own CMS that the new site is built in.
 

Join The Conversation

Moderators and Top Contributors

Hot Threads This Week

Featured Threads

Free SEO Tools

Hire Expert Members