重写PHP友好的URL使用.htaccess文件多种语言 [英] Rewrite Friendly php URL for multiple languages using .htaccess file

查看:158
本文介绍了重写PHP友好的URL使用.htaccess文件多种语言的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有我建立了一个不育系,将节省的语言在一个XML文件,并根据不同的页面,语言选择,它会显示正确的数据一对夫妇的网站。我cuurently对每个站点的8种不同的语言和URL是这样的:

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

我想拥有它,这样的URL重写为如下:

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

我花了几个小时通过论坛梳理和没有能够找到一个解决方案,工程。我的.htaccess文件现在看起来是这样的:

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]

这并没有做任何事情,该网址仍是丑陋的继女版。上面的链接是实际联系的地点之一。有一次,我整理了这一点,我需要它deply几个地点,但被伤透我的头试图理清了这一点。谁能告诉我什么,我做错了什么?

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?

推荐答案

这应该工作在一个.htaccess文件的根目录下:

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]

这篇关于重写PHP友好的URL使用.htaccess文件多种语言的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆