Forum Moderators: phranque

Message Too Old, No Replies

htaccess rewrite - rewrite some characters in some product URLs

         

webwest

7:31 pm on Feb 15, 2011 (gmt 0)

10+ Year Member



We have an ecommerce store with 100K products. Our inventory is automated and comes from our distributor and our redirects work in the form of /productcode.html

About 500 products from our distributor are not redirecting correctly because they have a + in the product code as well as are missing other characters. Our distributor won't change the codes ...

Our gotcha is that only the product codes that start with "B+B" need to rewrite to "B%252BB"

I.E. product B+B1014.html needs to rewrite to B%252BB1014.html

Any guidance on this would be greatly appreciated.

Thanks!

jdMorgan

12:02 am on Feb 18, 2011 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



We need more "scope" on this problem. For example, do you currently rewrite the "good" numerical URLs to a script, passing the product number as a query string?

If so, the change must be fully-integrated with that existing code, so that chained/stacked rewrites do not take place. Otherwise, you will trigger a known apache bug, and encounter big problems.

On its face this is not at all a difficult problem, and RewriteCond or RewriteRule can test the requested URL-path for "B\+B" at the beginning, and rewrite that to B%2BB (you probably do NOT want to rewrite it to the doubly-encoded "B%252BB" as shown above).

RewriteRule ^B\+B([0-9]+)$ /B\%2BB$1 [NE,L]

But as stated, this function needs to be integrated with any further rules that would apply, so that these requests will be rewritten to their final destination filepath with a single rule.

Jim