Htaccess redirect directory name to parameter

I would like to redirect all the paths as follows:

myurl.com/worldwide/en myurl.com/worldwide/pt myurl.com/worldwide/de 

in

 myurl.com/worldwide/index.php?lang=en myurl.com/worldwide/index.php?lang=pt myurl.com/worldwide/index.php?lang=de 

Just to clear the dynamic pathname redirection after /worldwide

Actually, ideally, I would like to keep the original url (for example, myurl.com/worldwide/de ), but load the same php file with the language directory as a parameter, but not sure if this is possible?

thanks

+6
source share
2 answers

Use this code

 RewriteEngine On RewriteBase /worldwide/ RewriteCond %{REQUEST_FILENAME} !-f RewriteCond %{REQUEST_FILENAME} !-d RewriteRule ^(.*)$ index.php?lang=$1 [L,QSA] 

Please let me know if this helps you.

+9
source
 RewriteEngine on RewriteBase / RewriteCond %{REQUEST_FILENAME} !-d RewriteCond %{REQUEST_FILENAME}.php -f RewriteRule ^ %{REQUEST_URI}.php [L,NC] RewriteCond %{REQUEST_FILENAME} !-d RewriteCond %{REQUEST_FILENAME} !-f RewriteCond %{REQUEST_FILENAME}.php !-f RewriteRule ^(.+)$ /index.php?page=$1 [L,QSA] 
-1
source

All Articles