Welcome to WebmasterWorld Guest from 54.160.131.144

Forum Moderators: Ocean10000 & incrediBILL & phranque

Message Too Old, No Replies

Site Wide Parameter Redirect

     

GF_Diablos

7:40 am on May 18, 2010 (gmt 0)

5+ Year Member



Hey guys,

Got myself stuck on a little htaccess thing here.
I am looking to rewrite a dynamic parameter to static url but it appears in multiple locations, due to a #*$!ty CMS.

i.e.

www.example.com/blue-product.html?foo=bar
www.example.com/red-product.html?foo=bar
www.example.com/product-list.html?foo=bar

How do I write a redirect to catch the potentially hundreds of pages this could appear on, I tried using my usual redirect code with a wild card but this didn't fly.

The bigger problem I am facing? I need to keep the page on the product .html url ie. blue-product.html so ideally I cannot rewrite the urls to blue-product/foo/bar/ because of some external factors. I can get away with a different url as long as it ends with blue-product.html however so the target url may be something like;

http://www.example.com/foo/bar/blue-product.html

Or anything similar tbh I am open to suggestions.

g1smd

8:32 am on May 18, 2010 (gmt 0)

WebmasterWorld Senior Member g1smd is a WebmasterWorld Top Contributor of All Time 10+ Year Member Top Contributors Of The Month



RewriteRule cannot change URLs. URLs are defined by the links on your pages.

You need to link to the URL you want the user to see and use in the HREF value of the links on your pages.

A Rewrite connects that URL request to the actual internal filename of the content inside the server, without revealing what that internal filename is.

Once you have the rewrite serving the content, adding a redirect to redirect users asking for the old URL so that are told to now use the new URL will tidy your searchengine results up too.

Using RewriteRule the whole lot is usually less than half a dozen lines of code.

GF_Diablos

9:47 am on May 18, 2010 (gmt 0)

5+ Year Member



sorry I did mean using a rewrite rule with an accompanying redirect, I was just talking shorthand but can see how that would be an issue

jdMorgan

4:51 pm on May 18, 2010 (gmt 0)

WebmasterWorld Senior Member jdmorgan is a WebmasterWorld Top Contributor of All Time 10+ Year Member



> http://www.example.com/foo/bar/blue-product.html

If the parameter-name used in the internal query-based filepath is always "foo," then there may be no need to include it in the 'friendly' URL. So perhaps you can use only
http://www.example.com/bar/blue-product.html

Be aware that any objects included on the "blue-product.html" page must be referenced using server-relative links or absolute URLs. If such objects are referred to as page-relative links, the browser will request them from a subdirectory named "/foo/bar" and this will likely return a 404 error. So use <img src="/images/logo.gif"> or <img src="http://example.com/images/logo.gif"> instead of trying to use <img src="images/logo.gif"> or <img src="../images/logo.gif">

Jim

GF_Diablos

12:57 pm on May 20, 2010 (gmt 0)

5+ Year Member



I think I may go down the much easier route of modifying the stupid cms so it doesn't actually generate these URLs, I wouldn't care so much but Google seems to do it's best to index them despite me telling it to ignore them

Thanks for the advice guys

g1smd

4:55 pm on May 20, 2010 (gmt 0)

WebmasterWorld Senior Member g1smd is a WebmasterWorld Top Contributor of All Time 10+ Year Member Top Contributors Of The Month



The most basic fix is for the CMS to link only to the correct URLs for the content, but mod_Rewrite can perform an extra level of security in preventing access to all other improper URL formats.
 

Featured Threads

Hot Threads This Week

Hot Threads This Month