简体   繁体   English

使用.htaccess文件重写多种语言的友好php URL

[英]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. 我有几个网站,我为此建立了一个CMS,将这些语言保存在XML文件中,并且根据页面和语言选择器,它将显示正确的数据。 I cuurently have 8 different languages for each of the sites and the urls are like: 我目前对每个网站都有8种不同的语言,网址如下:

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

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

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

I am trying to have it so that the urls are rewritten to look like this: 我正在尝试使用它,以便将URL重写为如下所示:

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

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

http://leclosdamboise.com/de/hotel.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: 我的.htaccess文件当前如下所示:

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. 这没有任何作用,URL仍然是丑陋的继女版本。 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: 这应该在根目录下的一个.htaccess文件中工作:

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]

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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