开发者

.htaccess add hidden php get variable for language selection

I have a multiple language website, and I use a php get variable to set the cookie for the language setting. 开发者_运维技巧 I have multiple subfolders (http://www.site.com/es and http://www.site.com/de) that each have a respective .htaccess file. When accessing these folders, the .htaccess file does this to "silently" redirect the user and add the appropriate php variable:

-------
Options +FollowSymlinks
RewriteEngine on
RewriteOptions MaxRedirects=10
rewriterule ^http://www.site.com/es/$ http://www.site.com/?l=es [P,R=301]
rewriterule ^(.*)$ http://www.site.com/$1?l=es [P,R=301]
-------

When someone accesses the root directory: http://www.site.com, I want to add a ?l=en suffix "silently" to the url. How do I do that? Thanks.


I don't think it's possible in the method you want.

However, you could (in a round about way) modify your code:

RewritRule ... proxy_add_l.php

In which, the code would:

<?php
$_GET['l'] = $_REQUEST['l'] = 'en';
require 'index.php';
?>

Note this is really, really, bad, and should only be used as a last resort really.

Can't you just redirect them to /en which looks cleaner?


I think if you want a fixed value this is perfect possible with something like this:

rewriterule ^http://www.site.com/$ http://www.site.com/?l=en ...

I cant test the result cause am not at home now.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜