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 valueRewriteCond %{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]