Url rewriting rule
-
Hello there, I need some clever regular expression writing in IIS7 to redirect traffic from one site to another, the pages are similar in structure but information needs re-writing. Here's an example: http://www.mysite.com/manufacturers/Name\_of\_Manufacturer\_6828/Name\_OF\_Product\_43146.htm needs to be structured as the following http://www.newsite.co.in/free-msds-download/name-of-manufacturer/name-of-product/ Here's what needs changing: 1). Only Alpha, Numeric and hyphen's allowed. 2). Change '_' to '-'. 3). Remove the '_NUMBER' directly after the manufacturer name and before the '/'. 4). Remove the '_NUMBER' directly after the product name and before the '.htm'. 5). Remove the '.htm' and replace with a '/'. It needs writing into the code below please as a permanent 301 redirect:
-
Hello there, I need some clever regular expression writing in IIS7 to redirect traffic from one site to another, the pages are similar in structure but information needs re-writing. Here's an example: http://www.mysite.com/manufacturers/Name\_of\_Manufacturer\_6828/Name\_OF\_Product\_43146.htm needs to be structured as the following http://www.newsite.co.in/free-msds-download/name-of-manufacturer/name-of-product/ Here's what needs changing: 1). Only Alpha, Numeric and hyphen's allowed. 2). Change '_' to '-'. 3). Remove the '_NUMBER' directly after the manufacturer name and before the '/'. 4). Remove the '_NUMBER' directly after the product name and before the '.htm'. 5). Remove the '.htm' and replace with a '/'. It needs writing into the code below please as a permanent 301 redirect:
Hi, You can use the JavaScript below,
var str="http://www.mysite.com/manufacturers/Name\_of\_Manufacturer\_6828/Name\_OF\_Product\_43146.htm";
str=str.replace("http://www.mysite.com/manufacturers/", "");
var key=str.split("/");
var manufacturer=key[0];
var product=key[1];
var to_index=manufacturer.lastIndexOf("_", manufacturer.length);
manufacturer=manufacturer.substring(0, to_index);
manufacturer=manufacturer.replace(/_/gi, "-");product=product.replace(/.htm/gi, "");
to_index=product.lastIndexOf("_", product.length);
product=product.substring(0, to_index);
product=product.replace(/_/gi, "-");
var cleanUrl="http://www.newsite.co.in/free-msds-download/"+manufacturer+"/"+product+"/";
document.write(cleanUrl);variable
cleanUrl
holds the url you are looking for.Hope this will help. -
Hello there, I need some clever regular expression writing in IIS7 to redirect traffic from one site to another, the pages are similar in structure but information needs re-writing. Here's an example: http://www.mysite.com/manufacturers/Name\_of\_Manufacturer\_6828/Name\_OF\_Product\_43146.htm needs to be structured as the following http://www.newsite.co.in/free-msds-download/name-of-manufacturer/name-of-product/ Here's what needs changing: 1). Only Alpha, Numeric and hyphen's allowed. 2). Change '_' to '-'. 3). Remove the '_NUMBER' directly after the manufacturer name and before the '/'. 4). Remove the '_NUMBER' directly after the product name and before the '.htm'. 5). Remove the '.htm' and replace with a '/'. It needs writing into the code below please as a permanent 301 redirect:
I am going to make a few assumptions. Since you said this is in IIS, you probably can't create .Net or JavaScript code to handle the redirect (i.e., all redirects must be done using some regexes in a configuration file). Also, I assume the number of underscores in the "mysite.com" URL is variable. I don't think you can do this with one redirect, but you can create several. For example, you can start off with these (create more to handle more underscores):
^http://www\.mysite\.com/manufacturers/(?<MAN>[a-z0-9]+)_[0-9]+/(?<PRO>[a-z9-9]+)_[0-9]+\.htm$
http://www\.newsite\.co\.in/free-msds-download/${MAN}/${PRO}/^http://www\.mysite\.com/manufacturers/(?<MAN1>[a-z0-9]+)_(?<MAN2>[a-z0-9]+)_[0-9]+/(?<PRO>[a-z0-9]+)_[0-9]+\.htm$
http://www\.newsite\.co\.in/free-msds-download/${MAN1}-${MAN2}/${PRO}/^http://www\.mysite\.com/manufacturers/(?<MAN>[a-z0-9]+)_[0-9]+/(?<PRO1>[a-z9-9]+)_(?<PRO2>[a-z9-9]+)_[0-9]+\.htm$
http://www\.newsite\.co\.in/free-msds-download/${MAN}/${PRO1}-${PRO2}/^http://www\.mysite\.com/manufacturers/(?<MAN1>[a-z0-9]+)_(?<MAN1>[a-z0-9]+)_[0-9]+/(?<PRO1>[a-z9-9]+)_(?<PRO2>[a-z9-9]+)_[0-9]+\.htm$
http://www\.newsite\.co\.in/free-msds-download/${MAN1}-${MAN2}/${PRO1}-${PRO2}/That is simple enough, but that could end up being a lot of rules if you have a large range of underscores (e.g., "the_name_of_some_long_product" and "the_name_of_some_long_manufacturer"). Alternatively, you can redirect all of the "mysite" URL's that match the pattern you want to a single URL on "newsite" that takes the original URL as a query string. The page on newsite can then parse the query string and perform a redirect using C# or VB.Net code, which gives you more flexibility than a configuration file. Note: the above regexes are untested and may contain mistakes, but you get the idea.
Somebody in an online forum wrote:
INTJs never really joke. They make a point. The joke is just a gift wrapper.