Forum Moderators: phranque

Message Too Old, No Replies

301 variables .htaccess

         

Johhny78

10:52 am on Aug 10, 2012 (gmt 0)

10+ Year Member



Hello everyone,

We have 2 webstores: 1 based on Magento and the other on an old package crappy package (both on a different domain). We kept the old store on for a while, because it had some regular customers, however now we want to refer all customers (and google traffic) to the new store/site/domain.

We do want to refer all articles to the corresponding page in the new store. I figured this would be easy as pie and just set up some 301's and be done with it. However it is proving to be more difficult than I initially expected. The issue:
*Old URL: www.example.com/index.php?item=article_name?action=article&group_id=number?aid=number_in_group?lang=EN (or FR for our French translation of the site)
So there's a few variables: the name of the article (item), the group_id, the aid and the lang. The action is always the same.
*New URL is a lot more clear: www.example.com/brand/article.html

I started off with a simple
Redirect 301 /index.php?item=article_name?action=article&group_id=number?aid=number_in_group?lang=EN http://www.example.com/brand/article.html

However this results in the page redirecting to the new domain with '/index.php?item=article_name?action=article&group_id=number?aid=number_in_group?lang=EN' after the URL, which doesn't work.

I then did a lot of googling, but really ended up stuck with how to properly phrase the rewritengine:

Options +FollowSymlinks
RewriteEngine on

ReWriteCond %{THE_REQUEST} item=([^name]+)&group_id=([^number]+)&lang=([^EN]+)*\ HTTP/
RewriteRule . http://www.example.com/brand/article.html? [R=301,L]


I know the above is wrong, but as this is far from my specialty I am at a loss as to how to make it work.

Any help is greatly appreciated!

g1smd

12:22 pm on Aug 10, 2012 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



[^name]+
matches a name that does NOT contain an "n" or "a" or "m" or "e".
Likewise for
[^number]+
.

Has your old URL really got multiple question marks in it?

Does the actual "brand" name, and "article" name appear in the old URL anywhere?

Johhny78

3:13 pm on Aug 10, 2012 (gmt 0)

10+ Year Member



g1smd, terribly sorry, the correct line is:

www.example.com/index.php?item=article_name&action=article&group_id=number&aid=number_in_group&lang=EN

So the last 3 '?' 's were supposed to be '&'s.

As for the brand and article name, only the article name appears in some of both the URLs. So it could be:

www.example.com/index.php?item=iphone&action=article&group_id=number&aid=number_in_group&lang=EN

and

http://www.example.com/Apple/iphone.html

But it is not 100% consistent in URLs.

lucy24

10:16 pm on Aug 10, 2012 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



The magic words are {QUERY_STRING}. Search this forum.

Johhny78

9:57 am on Aug 11, 2012 (gmt 0)

10+ Year Member



Thanks Lucy, I feel a bit ashamed I didn't stumble upon it before.

I have been messing around and the following worked for me:

RewriteCond %{QUERY_STRING} ^item=a&action=b&group_id=c&aid=d&lang=e
RewriteRule ^index.php$ http://www.example.com/brand/article.html? [L,R=301]


Initially it didn't work because I used 'RewriteRule ^/index.php$', but without the slash, it works just fine.

Thanks again.

[edited by: Johhny78 at 10:04 am (utc) on Aug 11, 2012]

Johhny78

9:58 am on Aug 11, 2012 (gmt 0)

10+ Year Member



Double

g1smd

1:03 pm on Aug 11, 2012 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



Don't forget to escape literal periods in patterns.