1
  1. I have a htaccess code that redirects all the requests from /forum1/product to /product. The code in /forum1/product/.htaccess is as follows:

    <IfModule mod_rewrite.c>
    RewriteEngine On
    RewriteBase /
    RewriteRule ^(.*)$ /product/$1 [PT,L]
    </IfModule>
    

    This code works perfectly for "/forum1/product/", "/forum2/product/", "forum3/product/",... etc. so all my forums are using the same product code(also I have used $_SERVER['HTTP_REFERER'] in product code so that product responds distinctly for each forum).

2.

I have a new version of product which I don't want to make live yet. So am trying to set a cookie "version" and based on the version it should redirect to corresponding product_<version number> folder by referring:
How to do htaccess redirect based on cookie value

  RewriteCond %{HTTP_COOKIE} ^version=([0-9]*)$ [NC] 
  RewriteRule .* http://localhost/product_%1/ [R=301,L]
  RewriteRule .* http://local-host/product/ [R=301,L]

Both 1 and 2 works fine seperately. I want to merge these two conditions.

So if cookie "version" is set to 2 then /forum/product redirects to /product_2 but still shows the URL /forum/product but it will be using /product_2

The folder structure is as follows:

/forum1/product/.htaccess
/forum2/product/.htaccess
/forum3/product/.htaccess
/product/version.txt
/product_1/version.txt
/product_2/version.txt

I think the following code should work:

RewriteEngine on
RewriteBase /
RewriteCond %{HTTP_COOKIE} ^version=([0-9]*)$ [NC]
RewriteRule ^(.*)$ /product_%1/$1 [PT,L]
RewriteRule ^(.*)$ /product/$1 [PT,L]
Community
  • 1
  • 1
Ketan Yekale
  • 1,821
  • 3
  • 20
  • 32

2 Answers2

1

Got the solution:

RewriteEngine on
RewriteBase /
RewriteCond %{HTTP_COOKIE} ^version=([0-9]*)$ [NC]
RewriteRule ^(.*)$ /product_%1/$1 [PT,L]
RewriteRule ^(.*)$ /product/$1 [PT,L]
Ketan Yekale
  • 1,821
  • 3
  • 20
  • 32
0

You can use:

RewriteEngine On

RewriteCond %{HTTP_COOKIE} version=([0-9]+) [NC] 
RewriteRule ^ /product_%1/ [L]

RewriteRule ^(.+)$ /product/$1 [L]
anubhava
  • 664,788
  • 59
  • 469
  • 547
  • The folder structure is:
    /forum1/product/.htaccess
    /forum2/product/.htaccess
    /forum3/product/.htaccess
    /product/version.txt
    /product_1/version.txt
    /product_2/version.txt
    if "cookie version" is set to 1 then http://localhost/forum1/product/version.txt should show 1
    – Ketan Yekale Feb 21 '14 at 12:56
  • I am confused about `version.txt` now as you didn't mention this in your question. Can you edit the question and clarify bit more. – anubhava Feb 21 '14 at 14:03