regex - Friendly php URL for multiple languages using htaccess file (detect language from URL) -


i have multi language php script use urls detecting language files should load template folder 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 want have more pretty , seo friendlier urls. need detect language nicer way urls.

for example:

english version: site.com/en/etc.php

arabic version: site.com/ar/etc.php

is possible .htaccess file? (i search solutions in stackoverflow, didn't work...)

thank amir

you can have these rules in 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] 

Comments

Popular posts from this blog

php - SPIP: From Tag directly to an article -

jquery - isAjaxRequest always return false -

ruby on rails - In a controller spec, how to find a specific tag in the generated view? -