2015-04-19 151 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規則

希望幫助您重定向到首頁?