I have a multi language php script which use URLs to detecting which language files should be load from template folder for user.
for example:
English version: site.com/etc.php or site.com/etc.php?lang=EN
Arabic version: site.com/etc.php?lang=AR
but I want to have more pretty and also SEO friendlier URLs. So I need to detect language by a nicer way from URLs.
for example:
English version: site.com/EN/etc.php
Arabic version: site.com/AR/etc.php
is this possible by .htaccess file? (I search for solutions in stackoverflow, but it didn't work...)
Thank you Amir
You can have these rules in your document root .htaccess:
RewriteEngine On
RewriteCond %{THE_REQUEST} \s/+([^.]+\.php)\?lang=([^\s&]+) [NC]
RewriteRule ^ /%2/%1? [R=301,L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^([A-Z]{2})/(.+?)/?$ /$2?lang=$1 [L,QSA,NC]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^([A-Z]{2})/?$ /?lang=$1 [L,QSA,NC]
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With