i'm not good in writing modrewrite access rules and would like to achieve the following scenario:
virtual url /en/shop.php redirects to /shop.php?lang=en
already got that but the actual problems are within the modrewrite environment:
if url is '/' (empty) --> redirect to /en/ (/index.php?lang=en)
if url is '/en' or '/de' --> redirect to /en/ or /de/ (add slash)
if an uri is "defined" like /en/shop.php -> redirect to /shop.php?lang=en
i've tried several rules but the last one results in a endless loop and i can't figure out what's wrong .. :/ please help
here's my .htaccess file:
RewriteEngine On
RewriteBase /
# empty url -> redirect to en/
RewriteRule ^$ en/ [R=301,L]
# url is ONLY '/en' or '/de' -> redirect to /en/ or /de/ (adding slash)
RewriteRule ^(en|de)$ $1/ [R=301,L]
# now all urls have en/ de/ -> parse them
RewriteRule ^(en|de)/(.*)$ $2?lang=$1&%{query_STRING} [R=301,L]
See Question&Answers more detail:os