我试图在新服务器上配置Nginx。我有很多PHP脚本(f.e )。/test/test.php),我希望使用这个脚本“原样”(默认语言、英语)以及语言重定向。示例-当请求"/de/test/test.php“时,
"/de/test/test.php"
任何帮助都是非常感谢的!我已经失去了几个晚上与此斗争,我变得非常绝望,取消新的服务器,并返回共享主机。
谢谢!
发布于 2011-10-10 16:25:57
在php位置下创建一个子位置:
location ~ ^.+\.php$ {
# Return '400 Bad Request' for malformed URL exploits
location ~ \..*/.*\.php$ {
return 400;
}
location ~ ^/de/(.+)\.php {
add_header Set-Cookie lang=de;
rewrite ^/de/(.+)\.php$ /$1.php last;
}
# Your proxy or fastcgi code to process PHP
...
}发布于 2012-09-01 13:55:47
我知道它很古老,但是如果其他人发现它有用的话,下面是我是如何解决这个问题的(在朋友的帮助下)。我在nginx中设置了LANG变量,然后在PHP $_SERVER['LANG']中获得了这个变量。
# languages
location ~ ^/(af|sq|ar|hy|az|be|bs|bg|cs|zh|da|de|nl|el|en|et|fa|fi|fr|ka|he|hi|hr|hu|id|it|ja|kk|ko|lv|lt|nb|no|pl|pt|ro|ru|sk|sl|es|sr|sv|th|tk|tr|uk|uz|vi|bp)/
{
set $lang $1;
rewrite ^/[^/]+/(.+)$ /$1 break;
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
fastcgi_intercept_errors on;
fastcgi_read_timeout 600;
include fastcgi_params;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
fastcgi_param LANG $lang;
}https://stackoverflow.com/questions/7704886
复制相似问题