I have in my .htaccess file the following code:
RewriteRule ^(en|af|fr)/(.*)$ - [co=lang:$1:mysite.info:7200:/] #drop/update cookie with lang
RewriteRule ^(en|af|fr)$ - [co=lang:$1:mysite.info:7200:/] #drop/update cookie with lang
RewriteRule ^(en|af|fr)$ / [R,NC]
RewriteRule ^(en|af|fr)/(.*)$ /$2 [R,NC]
In my php I have this for selecting the language:
<?php echo $_COOKIE['lang']; ?>
<ul>
<li><a href="/en<? echo $_SERVER['REQUEST_URI'];?>">en-ZA</a></li>
<li><a href="/fr<? echo $_SERVER['REQUEST_URI'];?>">fr-MU</a></li>
<li><a href="/af<? echo $_SERVER['REQUEST_URI'];?>">af-ZA</a></li>
</ul>
It semi-works, but it's not consistent. While I'm switching between languages it simply stops working, and then starts again if I keep clicking on the different languages.
SECOND PART of question:
How to reduce these lines:
RewriteCond %{http_host} ^www.mysite.info [nc] #if url starts with www.mysite.info
RewriteRule ^(.*)$ http://mysite.info/$1 [r,nc] #rewrite without the www
RewriteCond %{http_host} ^www.(.*).mysite.info [nc] #if url starts with www.(aff).mysite.info
RewriteRule ^(.*)$ http://%1.mysite.info/$1 [r,nc] #rewrite without the www
RewriteCond %{HTTP_HOST} !^www\. [NC]
RewriteCond %{http_host} ^(.*)\.mysite.info [nc] #if subdomain is aff
RewriteRule ^(.*)$ - [co=aff:%1:mysite.info:7200:/] #drop/update cookie with aff
RewriteCond %{HTTP_HOST} !^www\. [NC]
RewriteCond %{http_host} ^(.*)\.mysite.info [nc] #if subdomain is aff
RewriteRule ^(.*)$ http://mysite.info/$1 [nc,R] #rewrite without subdomain
Appreciate the help, anubhava!