Forum Moderators: phranque

Message Too Old, No Replies

Live Store Rewrite Htaccess Help!

htaccess problem rewrite url

         

davidhtn

6:13 pm on Nov 23, 2004 (gmt 0)

10+ Year Member



I was curious if anyone could help with a small problem I'm having, well big actually

I need to rewrite a incoming url from
http://www.example.com/store/product_info.php?ad=bizrate?products_id=33

to

http://www.example.com/store/product_info.php?ad=bizrate&products_id=33

only change is the? to a & behind ad=bizrate

its causing products not to show and could use a solution quickly if possible.

let me know
thanks
David

[edited by: jdMorgan at 10:18 pm (utc) on Nov. 23, 2004]
[edit reason] Obscured specifics per TOS [/edit]

jdMorgan

10:27 pm on Nov 23, 2004 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



I'm not sure if you're looking for a "point solution" to one particular URL, or for a more general solution that allows "ad" and "products" to be variable and/or exchange positions. Also not sure if you want a solution for use in your root directory or for use in the /store/product_info subdirectory.

Do you already have existing mod_rewrite code? If not, you'll need to add a few setup directives and make sure your server overrides and Options are set correctly.

Here's a point solution, devoid of any of the usual mod_rewrite setup stuff. If you need more, please see the references cited on our charter [webmasterworld.com] and please have a try at solving this yourself.


RewriteCond %{QUERY_STRING} ^ad=bizrate\?products_id=33
RewriteRule ^store/product_info\.php http://www.example.com/store/product_info.php?ad=bizrate&products_id=33 [R=301,L]

davidhtn

2:11 am on Nov 24, 2004 (gmt 0)

10+ Year Member



to explain the problem better, there is about 17,000 links pointing to the site incorrectly.
all i need to rewrite product_info.php?ad=bizrate?

to really be product_info.php?ad=bizrate&

where bizrate is would also be ad=froogle ad=yahoo
etc.

The problem is a "?" being sent after bizrate in the top example should really be a &
so this causes the normal url structure to fail.

I do have a current rewrite system in place as well.

i have tried many ways of doing it, but they all fail, time is short considering these are PPC links pointing.
please help if you can..

a1call

2:30 am on Nov 24, 2004 (gmt 0)

10+ Year Member



Hi I can never get the rules to work the first time but, the following should demonstrate the concept. I don't want to mess my own htaccsess.

RewriteRule (.*)?(.*) $1anyreservedword$2 [NE]
RewriteRule (.*)?(.*) $1&$2 [NE]
RewriteRule (.*)anyreservedword(.*) $1?$2 [NE]
Basically you can do it by 3 pattern maches.
1st change the first?
2nd change the remaining? to &
then chang back the first.
the anyreservedword should be a pattern that would not otherwise appear.

Hope it works.

jdMorgan

2:52 am on Nov 24, 2004 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



The main problem with that solution is that a query string is not considered to be part of a URL (a query string is data to be passed to a resource *at* a URL). Therefore, RewriteRule cannot "see" a query string unless you take steps to merge it with the URL manually.

The following approach demonstrates the use of RewriteCond to overcome this limitation.

Rewrite product_info.php?ad=bizrate?<anything> --> product_info.php?ad=bizrate&<anything> :


RewriteCond %{QUERY_STRING} ^ad=bizrate\?(.*)$
RewriteRule ^product_info\.php$ http://www.example.com/store/product_info.php?ad=bizrate&%1 [R=301,L]

This is an external redirect, and will have the effect of "correcting" those incorrect URLs which have been spidered by search engine robots.

Jim

davidhtn

3:17 am on Nov 24, 2004 (gmt 0)

10+ Year Member



thank you for the help,
however it didn't work =(

here is the htaccess file.
AddType application/x-shockwave-flash swf
RewriteEngine on
Options +FollowSymlinks
DirectoryIndex home.html home.php index.php index.html
AddType application/x-httpd-php php php4 php3 html htm
RewriteRule ^sitemap_categories.html$ sitemap_categories.php [L]
RewriteRule ^sitemap_products.html$ sitemap_products.php [L]
RewriteRule ^category_([1-9][0-9]*)_([1-9][0-9]*)_([1-9][0-9]*)_([1-9][0-9]*)_([1-9][0-9]*)_([1-9][0-9]*)\.htm$
RewriteRule ^category_([1-9][0-9]*)_([1-9][0-9]*)_([1-9][0-9]*)_([1-9][0-9]*)_([1-9][0-9]*)\.html$ index.php?c$
RewriteRule ^category_([1-9][0-9]*)_([1-9][0-9]*)_([1-9][0-9]*)_([1-9][0-9]*)\.html$ index.php?cPath=$1_$2_$3_$
RewriteRule ^category_([1-9][0-9]*)_([1-9][0-9]*)_([1-9][0-9]*)\.html$ index.php?cPath=$1_$2_$3 [L]
RewriteRule ^category_([1-9][0-9]*)_([1-9][0-9]*)\.html$ index.php?cPath=$1_$2 [L]
RewriteRule ^category_([1-9][0-9]*)\.html$ index.php?cPath=$1 [L]
RewriteRule ^product_([1-9][0-9]*)\.html$ product_info.php?&products_id=$1 [L]
RewriteRule (.*)?(.*) $1ad=bizrate$2 [NE]
RewriteRule (.*)?(.*) $1&$2 [NE]
RewriteRule (.*)ad=bizrate(.*) $1?$2 [NE]

I would thing this would work,
but I tried
/store/product_info.php?ad=bizrate?products_id=84
and it did not work,
but when i go to
/store/product_info.php?ad=bizrate&products_id=84
it still works, (which is good) but for some reason that didnt work.
this has me scratching my head.
btw where 84 is, that changes to thousands of numbers, im wondering if it needs to be set to handle the products_id= part then allow for any number after that to be handled as normal
:P

davidhtn

3:31 am on Nov 24, 2004 (gmt 0)

10+ Year Member



jim, thanks, I tried that but no go, im wondering now if maybe something i have in the existing htaccess is preventing that rewrite from working.
i have posted the htaccess file it looks ok to me, but you know more about this then i do :P

davidhtn

2:47 pm on Nov 24, 2004 (gmt 0)

10+ Year Member



jim,
RewriteCond %{QUERY_STRING} ^ad=bizrate\?(.*)$
RewriteRule ^store/product_info\.php$ [example.com...] [R=301,L]

and

RewriteCond %{QUERY_STRING} ^ad=([^?]+)\?(.*)$
RewriteRule ^store/product_info\.php$ [example.com...] [R=301,L]

no go for both, tried in both locations as well, in root, and in the /store/ directory.

now I'm glad you took our 'emergency' seriously, please understand it really is a true emergency, the links pointing to the site are not indexed search engine urls, these are submited Pay per click links which have already cost over $50, if that does not classify as one i dunno what does heh.

as for the solution, its still being proccessed by oscommerce incorrectly, its not picking up the change.
as for the problem, you understand fully what i need from the code above, but it simply don't work for me.

I think the best thing to do at this point is to disable the links.
somehow.

thanks.
david.

jdMorgan

6:47 pm on Nov 24, 2004 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



The only other thing I can think of is that maybe "/store" is an aliased directory. If that is the case, then your .htaccess file won't be in the real filepath between root and /store. If that's the case, then .htaccess won't be executed if requests are made for /store. You'd have to move these new rules --with a few minor changes-- into the httpd.conf <directory> container for /store.

Jim

davidhtn

7:27 pm on Nov 24, 2004 (gmt 0)

10+ Year Member



nope, not a alias.
heh

its ok, thanks for the help