简体   繁体   中英

Rewrite Friendly php URL for multiple languages using .htaccess file

I have a couple websites that I built a CMS for that will save the languages in an XML file and depending on the page and language selector, it will show the correct data. I cuurently have 8 different languages for each of the sites and the urls are like:

http://leclosdamboise.com/index.php?lang=fr

http://leclosdamboise.com/rooms.php?lang=en

http://leclosdamboise.com/hotel.php?lang=de

I am trying to have it so that the urls are rewritten to look like this:

http://leclosdamboise.com/fr/index.php

http://leclosdamboise.com/en/rooms.php

http://leclosdamboise.com/de/hotel.php

I have spent hours combing through forums and not been able to find a solution that works. My .htaccess file currently looks like this:

SetEnv PHP_VER 5_TEST
SetEnv REGISTER_GLOBALS 0

RewriteEngine on
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^([A-Za-z0-9]+)$ index.php?lang=$1 [QSA,L]

This does not do anything and the urls are still the ugly step-daughter version. The links above are actual links to one of the sites. Once I sort this out I need to deply it to several sites, but been racking my head trying to sort this out. Can anyone tell me what I'm doing wrong?

This should work in one .htaccess file at root directory:

Options +FollowSymlinks -MultiViews
RewriteEngine On
RewriteBase /

RewriteCond %{REQUEST_FILENAME} -f  [OR]
RewriteCond %{REQUEST_FILENAME} -d
RewriteRule .* - [L]

RewriteRule ^([^/]+)/([^.]+)\.php  /$2.php?lang=$1 [L,NC,QSA]

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM