Your SlideShare is downloading. ×
0
Htaccess with Cookies
Htaccess with Cookies
Htaccess with Cookies
Htaccess with Cookies
Htaccess with Cookies
Htaccess with Cookies
Htaccess with Cookies
Htaccess with Cookies
Htaccess with Cookies
Htaccess with Cookies
Htaccess with Cookies
Htaccess with Cookies
Htaccess with Cookies
Htaccess with Cookies
Upcoming SlideShare
Loading in...5
×

Thanks for flagging this SlideShare!

Oops! An error has occurred.

×
Saving this for later? Get the SlideShare app to save on your phone or tablet. Read anywhere, anytime – even offline.
Text the download link to your phone
Standard text messaging rates apply

Htaccess with Cookies

681

Published on

Published in: Technology
0 Comments
0 Likes
Statistics
Notes
  • Be the first to comment

  • Be the first to like this

No Downloads
Views
Total Views
681
On Slideshare
0
From Embeds
0
Number of Embeds
0
Actions
Shares
0
Downloads
0
Comments
0
Likes
0
Embeds 0
No embeds

Report content
Flagged as inappropriate Flag as inappropriate
Flag as inappropriate

Select your reason for flagging this presentation as inappropriate.

Cancel
No notes for slide

Transcript

  • 1. Htaccess - Complex redirections Cristina Martin, Web developer [email_address] epoint.ro: Epoint Web Solutions
  • 2. Table of Content <ul><li>Customer requirements </li></ul><ul><li>Problem analysis and solutions </li></ul><ul><ul><li>GeoIP </li></ul></ul><ul><ul><li>Cookies </li></ul></ul><ul><ul><li>.htaccess </li></ul></ul><ul><li>Proxy websites </li></ul><ul><li>Links/References </li></ul>
  • 3. Customer requirements <ul><li>Content sections of the website different for the available countries </li></ul><ul><li>An user from Germany will enter in the German section of the website with content in German language </li></ul><ul><li>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 </li></ul><ul><li>Multilingual website </li></ul>
  • 4. Solutions: GeoIP <ul><li>Geographic Internet Protocol address location </li></ul><ul><li>GeolP Country - regularly updated database with information about IP addresses issued for those countries </li></ul><ul><li>$country_code = apache_note(”GEOIP_COUNTRY_CODE”); </li></ul><ul><li>$country_name = apache_note(GEOIP_COUNTRY_NAME); </li></ul>
  • 5. Solutions: Cookies <ul><li>Used to retain the user preferences for country and language. </li></ul><ul><li>In case the user will return several times, should not be forced to make the settings again and again. </li></ul><ul><li>setcookie (&quot;Country&quot;, $ country, 0,'/'); </li></ul><ul><li>setcookie (&quot;Language&quot;, $ language, 0,'/'); </li></ul>
  • 6. Solutions: .htaccess <ul><li>Can be used to rewrite URLs </li></ul><ul><li>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 </li></ul><ul><li>Second case scenario: the visitor is automatically redirected in the preffered country's section with content in the language choosen by him through cookies </li></ul>
  • 7. .htaccess - First case <ul><li>RewriteCond %{ENV:GEOIP_COUNTRY_CODE} ^RO$ </li></ul><ul><li>RewriteCond %{REQUEST_URI} !^/index.php$ </li></ul><ul><li>RewriteCond %{HTTP_COOKIE} !^.*Language.*$ [NC] </li></ul><ul><li>RewriteCond %{HTTP_COOKIE} !^.*Country.*$ [NC] </li></ul><ul><li>RewriteRule ^(.*)$ /index.php?id=81&L=2 [L] </li></ul>
  • 8. .htaccess – First case <ul><li>[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. </li></ul><ul><li>[L] (last rule) - Stop the rewriting process here and don't apply any more rewrite rules </li></ul>
  • 9. .htaccess – First case <ul><li>First condition : If the user is in Romania; </li></ul><ul><li>The second condition : If the user has accessed www.ourdomain.com / index.php; </li></ul><ul><li>The third condition : If the cookie Language isn't set; </li></ul><ul><li>The fourth condition : If the cookie Country isn't set; </li></ul><ul><li>Rewrite rule : If all the conditions are met, the user is redirected to that URL </li></ul>
  • 10. .htaccess – Second case <ul><li>RewriteCond %{REQUEST_URI} !^/index.php$ </li></ul><ul><li>RewriteCond %{HTTP_COOKIE} Language=([^;]+) [NC] </li></ul><ul><li>RewriteRule ^(.*)$ /index.php?L=%1 [NC,C] </li></ul><ul><li>RewriteCond %{HTTP_COOKIE} Country=([^;]+) [NC] </li></ul><ul><li>RewriteRule ^(.*)$ /index.php?id=%1%2 [NC,L,QSA] </li></ul>
  • 11. .htaccess – Second case <ul><li>[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 </li></ul><ul><li>[QSA] (query string append) - Forces the rewriting engine to add a query string part of the existing string, instead of replacing it. </li></ul>
  • 12. .htaccess – Second case <ul><li>First condition : If the user has accessed www.ourdomain.com / index.php; </li></ul><ul><li>The second condition : take the value of the cookie Language </li></ul><ul><li>Rewrite rule : rewrite based on our cookie value </li></ul><ul><li>The third condition : take the value of the cookie Country </li></ul><ul><li>Rewrite rule : rewrite based on the values of our cookies Country and Language </li></ul>
  • 13. Proxy websites <ul><li>Check at the following links: </li></ul><ul><ul><li>With an IP in Poland: http://proxy.trash.pl/ </li></ul></ul><ul><ul><li>With an IP Germany: http://www.surf-proxy.de/ </li></ul></ul><ul><ul><li>With a USA IP: http://open-browser.com/ </li></ul></ul><ul><li>There are many proxy websites (google-it) </li></ul>
  • 14. Links/References <ul><li>http://geolite.maxmind.com/download/geoip/database/GeoLiteCountry/GeoIP.dat.gz </li></ul><ul><li>http://www.maxmind.com/app/mod_geoip </li></ul><ul><li>http://www.askapache.com/htaccess/htaccess-fresh.html#modrewrite2 </li></ul><ul><li>http://corz.org/serv/tricks/htaccess2.php </li></ul><ul><li>http://httpd.apache.org/docs/2.0/mod/mod_rewrite.html </li></ul>

×