Your SlideShare is downloading. ×
  • Like
  • Save
Htaccess with Cookies
Upcoming SlideShare
Loading in...5

Thanks for flagging this SlideShare!

Oops! An error has occurred.


Now you can save presentations on your phone or tablet

Available for both IPhone and Android

Text the download link to your phone

Standard text messaging rates apply

Htaccess with Cookies



Published in Technology
  • Full Name Full Name Comment goes here.
    Are you sure you want to
    Your message goes here
    Be the first to comment
    Be the first to like this
No Downloads


Total Views
On SlideShare
From Embeds
Number of Embeds



Embeds 0

No embeds

Report content

Flagged as inappropriate Flag as inappropriate
Flag as inappropriate

Select your reason for flagging this presentation as inappropriate.

    No notes for slide


  • 1. Htaccess - Complex redirections Cristina Martin, Web developer [email_address] Epoint Web Solutions
  • 2. Table of Content
    • Customer requirements
    • Problem analysis and solutions
      • GeoIP
      • Cookies
      • .htaccess
    • Proxy websites
    • Links/References
  • 3. Customer requirements
    • Content sections of the website different for the available countries
    • An user from Germany will enter in the German section of the website with content in German language
    • If the user from Germany prefer the content from the UK section and Polski language, on his return he will enter directly on the UK section of the website with content in Polski
    • Multilingual website
  • 4. Solutions: GeoIP
    • Geographic Internet Protocol address location
    • GeolP Country - regularly updated database with information about IP addresses issued for those countries
    • $country_code = apache_note(”GEOIP_COUNTRY_CODE”);
    • $country_name = apache_note(GEOIP_COUNTRY_NAME);
  • 5. Solutions: Cookies
    • Used to retain the user preferences for country and language.
    • In case the user will return several times, should not be forced to make the settings again and again.
    • setcookie ("Country", $ country, 0,'/');
    • setcookie ("Language", $ language, 0,'/');
  • 6. Solutions: .htaccess
    • Can be used to rewrite URLs
    • First case scenario: the visitor is automatically redirected in the related country's section, checked through the IP address of the user with content in the default country's language
    • Second case scenario: the visitor is automatically redirected in the preffered country's section with content in the language choosen by him through cookies
  • 7. .htaccess - First case
    • RewriteCond %{ENV:GEOIP_COUNTRY_CODE} ^RO$
    • RewriteCond %{REQUEST_URI} !^/index.php$
    • RewriteCond %{HTTP_COOKIE} !^.*Language.*$ [NC]
    • RewriteCond %{HTTP_COOKIE} !^.*Country.*$ [NC]
    • RewriteRule ^(.*)$ /index.php?id=81&L=2 [L]
  • 8. .htaccess – First case
    • [NC] (no-case) - This makes the test case-insensitive - differences between 'A-Z' and 'a-z' are ignored when is match with the current URL.
    • [L] (last rule) - Stop the rewriting process here and don't apply any more rewrite rules
  • 9. .htaccess – First case
    • First condition : If the user is in Romania;
    • The second condition : If the user has accessed / index.php;
    • The third condition : If the cookie Language isn't set;
    • The fourth condition : If the cookie Country isn't set;
    • Rewrite rule : If all the conditions are met, the user is redirected to that URL
  • 10. .htaccess – Second case
    • RewriteCond %{REQUEST_URI} !^/index.php$
    • RewriteCond %{HTTP_COOKIE} Language=([^;]+) [NC]
    • RewriteRule ^(.*)$ /index.php?L=%1 [NC,C]
    • RewriteCond %{HTTP_COOKIE} Country=([^;]+) [NC]
    • RewriteRule ^(.*)$ /index.php?id=%1%2 [NC,L,QSA]
  • 11. .htaccess – Second case
    • [C] (chained with next rule) - Chains the current rule with the next rule. If a rule matches, then the rule is processed further, but if the rule does not match, then all the following chained rule will not be processed
    • [QSA] (query string append) - Forces the rewriting engine to add a query string part of the existing string, instead of replacing it.
  • 12. .htaccess – Second case
    • First condition : If the user has accessed / index.php;
    • The second condition : take the value of the cookie Language
    • Rewrite rule : rewrite based on our cookie value
    • The third condition : take the value of the cookie Country
    • Rewrite rule : rewrite based on the values of our cookies Country and Language
  • 13. Proxy websites
    • Check at the following links:
      • With an IP in Poland:
      • With an IP Germany:
      • With a USA IP:
    • There are many proxy websites (google-it)
  • 14. Links/References