Movatterモバイル変換


[0]ホーム

URL:


Uploaded bykristine2011
893 views

Htaccess with Cookies

The document discusses using .htaccess files and cookies to implement country and language redirection on a website based on the user's geographic location or previously selected preferences. It provides code examples for redirecting users based on their IP address determined country to the corresponding section, or allowing them to access a preferred section based on language and country cookies set on previous visits. Resources on geoIP databases and .htaccess modrewrite rules are also referenced.

Embed presentation

Htaccess - Complex redirections Cristina Martin, Web developer [email_address] epoint.ro: Epoint Web Solutions
Table of Content Customer requirements Problem analysis and solutions GeoIP Cookies .htaccess Proxy websites Links/References
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
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);
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,'/');
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
.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]
.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
.htaccess – First case First condition : If the user is in Romania; The second condition : If the user has accessed www.ourdomain.com / 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
.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]
.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.
.htaccess – Second case First condition : If the user has accessed www.ourdomain.com / 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
Proxy websites Check at the following links: With an IP in Poland: http://proxy.trash.pl/ With an IP Germany: http://www.surf-proxy.de/ With a USA IP: http://open-browser.com/ There are many proxy websites (google-it)
Links/References http://geolite.maxmind.com/download/geoip/database/GeoLiteCountry/GeoIP.dat.gz  http://www.maxmind.com/app/mod_geoip http://www.askapache.com/htaccess/htaccess-fresh.html#modrewrite2 http://corz.org/serv/tricks/htaccess2.php http://httpd.apache.org/docs/2.0/mod/mod_rewrite.html

Recommended

PPT
Htaccess with Cookies
PPT
Htaccess with Cookies
PPT
htaccess with Cookies
PPTX
Multilanguage and Location Complexity in International Websites
PPTX
PDF
Mass Report Generation Using REST APIs
PPTX
Using Aggregation for analytics
PPTX
Analysis of Air Pollution in Nova Scotia Presentation
PDF
Lightning Talk - Damien Thouvenin
PDF
Lightning talk flupa ux day
PDF
Adopting Agile Tools & Methods In A Legacy Context
PDF
Leadership talents
PDF
Jeux d'Innovation (FLUPA UX Day 2013)
PDF
Innovation games + agile in retail banking
PDF
Atelier "SOS du Titanic, perdu dans l'Atlantique" - leadership des talents
PPT
Peter Keating Dec2008
TXT
Htaccess
PDF
International sites hreflang
PPT
Comparative Development Methodologies
KEY
mod_rewrite
PDF
Htaccess file tutorial and tips
KEY
mod_rewrite bootcamp, Ohio LInux 2011
TXT
Htaccess
PPT
International sites hreflang video slides
KEY
URL Mapping, with and without mod_rewrite
PDF
Internationalizing CakePHP Applications
PDF
testing pdf doc
PDF
test pdf

More Related Content

PPT
Htaccess with Cookies
PPT
Htaccess with Cookies
PPT
htaccess with Cookies
PPTX
Multilanguage and Location Complexity in International Websites
PPTX
PDF
Mass Report Generation Using REST APIs
PPTX
Using Aggregation for analytics
PPTX
Analysis of Air Pollution in Nova Scotia Presentation
Htaccess with Cookies
Htaccess with Cookies
htaccess with Cookies
Multilanguage and Location Complexity in International Websites
Mass Report Generation Using REST APIs
Using Aggregation for analytics
Analysis of Air Pollution in Nova Scotia Presentation

Viewers also liked

PDF
Lightning Talk - Damien Thouvenin
PDF
Lightning talk flupa ux day
PDF
Adopting Agile Tools & Methods In A Legacy Context
PDF
Leadership talents
PDF
Jeux d'Innovation (FLUPA UX Day 2013)
PDF
Innovation games + agile in retail banking
PDF
Atelier "SOS du Titanic, perdu dans l'Atlantique" - leadership des talents
PPT
Peter Keating Dec2008
Lightning Talk - Damien Thouvenin
Lightning talk flupa ux day
Adopting Agile Tools & Methods In A Legacy Context
Leadership talents
Jeux d'Innovation (FLUPA UX Day 2013)
Innovation games + agile in retail banking
Atelier "SOS du Titanic, perdu dans l'Atlantique" - leadership des talents
Peter Keating Dec2008

Similar to Htaccess with Cookies

TXT
Htaccess
PDF
International sites hreflang
PPT
Comparative Development Methodologies
KEY
mod_rewrite
PDF
Htaccess file tutorial and tips
KEY
mod_rewrite bootcamp, Ohio LInux 2011
TXT
Htaccess
PPT
International sites hreflang video slides
KEY
URL Mapping, with and without mod_rewrite
PDF
Internationalizing CakePHP Applications
PDF
testing pdf doc
PDF
test pdf
PPT
Joomla! Day UK 2009 .htaccess
PDF
Nginx Workshop Aftermath
PDF
Apache Server Tutorial
ODP
Silverstripe 2.4-highlights-gpmd
PDF
Apache and PHP: Why httpd.conf is your new BFF!
PDF
Масштабируемая конфигурация Nginx, Игорь Сысоев (Nginx)
 
Htaccess
International sites hreflang
Comparative Development Methodologies
mod_rewrite
Htaccess file tutorial and tips
mod_rewrite bootcamp, Ohio LInux 2011
Htaccess
International sites hreflang video slides
URL Mapping, with and without mod_rewrite
Internationalizing CakePHP Applications
testing pdf doc
test pdf
Joomla! Day UK 2009 .htaccess
Nginx Workshop Aftermath
Apache Server Tutorial
Silverstripe 2.4-highlights-gpmd
Apache and PHP: Why httpd.conf is your new BFF!
Масштабируемая конфигурация Nginx, Игорь Сысоев (Nginx)
 

Recently uploaded

PDF
TrustArc Webinar - Looking Ahead: The 2026 Privacy Landscape
PDF
API-First Architecture in Financial Systems
PDF
Day 2 - Network Security ~ 2nd Sight Lab ~ Cloud Security Class ~ 2020
PPTX
From Backup to Resilience: How MSPs Are Preparing for 2026
 
PPTX
Chapter 3 Introduction to number system.pptx
PPTX
Protecting Data in an AI Driven World - Cybersecurity in 2026
PDF
Internet_of_Things_IoT_for_Next_Generation_Smart_Systems_Utilizing.pdf
PPTX
Ethics in AI - Artificial Intelligence Fundamentals.pptx
PDF
Zero Trust & Defense-in-Depth: The Future of Critical Infrastructure Security
PPTX
THIS IS CYBER SECURITY NOTES USED IN CLASS ON VARIOUS TOPICS USED IN CYBERSEC...
PDF
Vibe Coding vs. Spec-Driven Development [Free Meetup]
PPTX
Kanban India 2025 | Daksh Gupta | Modeling the Models, Generative AI & Kanban
PDF
Day 3 - Data and Application Security - 2nd Sight Lab Cloud Security Class
PPTX
Building Cyber Resilience for 2026: Best Practices for a Secure, AI-Driven Bu...
PDF
Security Technologys: Access Control, Firewall, VPN
PDF
Decoding the DNA: The Digital Networks Act, the Open Internet, and IP interco...
PPTX
Data Privacy and Protection: Safeguarding Information in a Connected World
PDF
GPUS and How to Program Them by Manya Bansal
PDF
Unlocking the Power of Salesforce Architecture: Frameworks for Effective Solu...
PDF
Usage Control for Process Discovery through a Trusted Execution Environment
TrustArc Webinar - Looking Ahead: The 2026 Privacy Landscape
API-First Architecture in Financial Systems
Day 2 - Network Security ~ 2nd Sight Lab ~ Cloud Security Class ~ 2020
From Backup to Resilience: How MSPs Are Preparing for 2026
 
Chapter 3 Introduction to number system.pptx
Protecting Data in an AI Driven World - Cybersecurity in 2026
Internet_of_Things_IoT_for_Next_Generation_Smart_Systems_Utilizing.pdf
Ethics in AI - Artificial Intelligence Fundamentals.pptx
Zero Trust & Defense-in-Depth: The Future of Critical Infrastructure Security
THIS IS CYBER SECURITY NOTES USED IN CLASS ON VARIOUS TOPICS USED IN CYBERSEC...
Vibe Coding vs. Spec-Driven Development [Free Meetup]
Kanban India 2025 | Daksh Gupta | Modeling the Models, Generative AI & Kanban
Day 3 - Data and Application Security - 2nd Sight Lab Cloud Security Class
Building Cyber Resilience for 2026: Best Practices for a Secure, AI-Driven Bu...
Security Technologys: Access Control, Firewall, VPN
Decoding the DNA: The Digital Networks Act, the Open Internet, and IP interco...
Data Privacy and Protection: Safeguarding Information in a Connected World
GPUS and How to Program Them by Manya Bansal
Unlocking the Power of Salesforce Architecture: Frameworks for Effective Solu...
Usage Control for Process Discovery through a Trusted Execution Environment

Htaccess with Cookies

  • 1.
    Htaccess - Complexredirections Cristina Martin, Web developer [email_address] epoint.ro: Epoint Web Solutions
  • 2.
    Table of ContentCustomer requirements Problem analysis and solutions GeoIP Cookies .htaccess Proxy websites Links/References
  • 3.
    Customer requirements Contentsections 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 GeographicInternet 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 Usedto 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 Canbe 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 - Firstcase 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 – Firstcase [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 – Firstcase First condition : If the user is in Romania; The second condition : If the user has accessed www.ourdomain.com / 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 – Secondcase 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 – Secondcase [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 – Secondcase First condition : If the user has accessed www.ourdomain.com / 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 Checkat the following links: With an IP in Poland: http://proxy.trash.pl/ With an IP Germany: http://www.surf-proxy.de/ With a USA IP: http://open-browser.com/ There are many proxy websites (google-it)
  • 14.
    Links/References http://geolite.maxmind.com/download/geoip/database/GeoLiteCountry/GeoIP.dat.gzhttp://www.maxmind.com/app/mod_geoip http://www.askapache.com/htaccess/htaccess-fresh.html#modrewrite2 http://corz.org/serv/tricks/htaccess2.php http://httpd.apache.org/docs/2.0/mod/mod_rewrite.html

[8]ページ先頭

©2009-2025 Movatter.jp