homepage Welcome to WebmasterWorld Guest from 54.227.5.234
register, free tools, login, search, subscribe, help, library, announcements, recent posts, open posts,
Accredited PayPal World Seller

Home / Forums Index / Code, Content, and Presentation / Apache Web Server
Forum Library, Charter, Moderators: Ocean10000 & incrediBILL & phranque

Apache Web Server Forum

    
Site Wide Parameter Redirect
GF_Diablos




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

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




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

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




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

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




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

> 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




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

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




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

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.

Global Options:
 top home search open messages active posts  
 

Home / Forums Index / Code, Content, and Presentation / Apache Web Server
rss feed

All trademarks and copyrights held by respective owners. Member comments are owned by the poster.
Terms of Service ¦ Privacy Policy ¦ Report Problem ¦ About
© Webmaster World 1996-2014 all rights reserved