Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

how to interpret domain/en as domain?lang=en

example of a subdomain – lorem.example.com
the only one sinle page inside – index.php
and one $_GET param – named lang

lorem.example.com/en – should be interpreted as – lorem.example.com?lang=en
lorem.example.com/de – should be interpreted as – lorem.example.com?lang=de

here is my try, without success

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

RewriteEngine ON
RewriteRule ^(en)/?$ $1.php [QSA,NC,L]  
RewriteRule ^(de)/?$ $1.php [QSA,NC,L]  

pls help

>Solution :

You may use this rule:

DirectoryIndex index.php
RewriteEngine On

RewriteRule ^(en|de)/?$ index.php?lang=$1 [QSA,NC,L]  

Here:

  • DirectoryIndex is useful (if not defined in Apache config) to serve index.php when request is just http://lorem.example.com
  • (en|de) matches and captures en or de in $1, that is used as value in lang parameter.
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading