skip to Main Content

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

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

2

Answers


  1. 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.
    Login or Signup to reply.
  2. With your shown samples please try following .htaccess rules file. Please make sure to clear your browser cache before testing your URLs.

    Make sure to keep your .htaccess and index.php files in same directory.

    RewriteEngine ON
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteRule ^([^/]*)/?$  index.php?lang=$1 [QSA,L]
    
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search