Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/254.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php 如何在htaccess中重写语言参数?_Php_.htaccess - Fatal编程技术网

Php 如何在htaccess中重写语言参数?

Php 如何在htaccess中重写语言参数?,php,.htaccess,Php,.htaccess,如何在htaccess中重写语言参数? 我想将url的第二部分设置为我的站点语言, 我在下面编写htaccess代码,但是当我打印$\u-GET时,没有发现$\u-GET['language'] 为什么? 顺便问一下,如何在htaccess中使用“?”或“&”进行抖动。我写了2秒钟的吼声,还有其他简单的方法吗 http://www.hello.com/en/test.html or http://www.hello.com/test.html //default language = en

如何在htaccess中重写语言参数?
我想将url的第二部分设置为我的站点语言,
我在下面编写htaccess代码,但是当我打印$\u-GET时,没有发现$\u-GET['language']
为什么?
顺便问一下,如何在htaccess中使用“?”或“&”进行抖动。我写了2秒钟的吼声,还有其他简单的方法吗

http://www.hello.com/en/test.html
or http://www.hello.com/test.html   //default language = en
=> 
http://www.hello.com/test.html?language=en

http://www.hello.com/fr/test.html
=> 
http://www.hello.com/test.html?language=fr

RewriteCond %{REQUEST_URI} ^\w{2}/.*\? [NC]
RewriteRule ^(.*)/(.*) $2&language=$1 [QSA,L]

RewriteCond %{REQUEST_URI} ^\w{2}/[^\?]* [NC]
RewriteRule ^(.*)/(.*) $2?language=$1 [QSA,L]

两个字符串是最简单的方法,因为您要么捕获参数,要么写入不存在的参数。说到
mod_rewrite
simple并不总是最好的方法。这应该适用于
QSA
。只要您声明一个新的查询字符串,QSA就会自动传递参数:

#Check for files that do not contain the language string
RewriteCond %{REQUEST_URI} !^/[a-z]{2}/.*
RewriteRule ^(.*)$ $1?language=en [QSA,L]

#Capture the language string and present it as the variable
RewriteCond %{REQUEST_URI} ^/([a-z]{2})/(.*)
RewriteRule ^.* %2?language=%1 [QSA,L]