2015-04-19 88 views
0

我使用WPML来翻译我的Wordpress网站,我不想使用Jquery语言重定向但使用htaccess。htaccess语言重定向与手动语言选择器

http://example.com是默认EN版本

http://example.com/de是德国一个

的问题是,当你重定向到/德/你不能手动导航到EN版本。

这里是我的代码

## Language Detection 

#The 'Accept-Language' header starts with 'de' 
#and the test is case-insensitive ([NC]) 
RewriteCond %{HTTP:Accept-Language} ^de [NC] 

#If not already redirected 
RewriteCond %{REQUEST_URI} !^/de/ [NC] # ADDED 

#Redirect user to /de/ address 
#sending 301 (Moved Permanently) HTTP status code 

RewriteRule ^$ /de/ [L,R=301] 

#For every other language use English 
RewriteRule ^$ - [L] # MODIFIED 

回答

0

我不知道你为什么不使用内置的浏览器语言重定向WPML提供? https://wpml.org/documentation/getting-started-guide/language-setup/automatic-redirect-based-on-browser-language/

使用WPML,您不应该通过.htaccess重定向,这被称为是有问题的方法。

我也发现了这个在WPML的论坛:

# BEGIN WordPress 
<IfModule mod_rewrite.c> 
RewriteEngine On 

# Redirect. Eg. Browser in German, redirect to /de/ 
RewriteCond %{REQUEST_URI} ^/$ 
RewriteCond %{HTTP:Accept-Language} (de) [NC] 
RewriteRule .* http://your-site.com/de/$1 [L] 

RewriteBase/
RewriteRule ^index\.php$ - [L] 
RewriteCond %{REQUEST_FILENAME} !-f 
RewriteCond %{REQUEST_FILENAME} !-d 
RewriteRule . /wp/index.php [L] 
</IfModule> 

# END WordPress 

我发现这个在这里: https://wpml.org/forums/topic/multiple-languages-without-cookies/ 并通过了码到您的德国的例子。

的一点是,你需要创建的标准语言的目录,与其它选择开关明智的语言将通过你的.htaccess规则

希望帮助您重定向到首页?