我在wordpress网站的根目录中有这个.htaccess文件。
RewriteEngine on
#For the spanish language, redirect to the spanish translation
RewriteCond %{HTTP:Accept-Language} ^es [NC]
RewriteRule ^$ %{REQUEST_URI}es/ [L,R=301]
#For every other language (including English) use English(the default)
RewriteRule ^$ %{REQUEST_URI}/ [L,R=301] #can remove this i know
这适用于网站的根目录。例如www.mysite.com,如果用户的浏览器语言有西班牙语默认值,它将重定向到www.mysite.com/es/
但是,如果用户点击另一个指向www.mysite.com/help/的链接,则不会以西班牙语加载帮助页面 - 预计会自动加载,www.mysite.com / help / es /
注意:
我如何实现这一目标?
在第一个答案之后,这是完整的mod_rewrite部分
# BEGIN WordPress
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteRule ^index\.php$ - [L]
RewriteRule ^assets/css/(.*) /wp-content/themes/mytheme/assets/css/$1 [QSA,L]
RewriteRule ^assets/js/(.*) /wp-content/themes/mytheme/assets/js/$1 [QSA,L]
RewriteRule ^assets/img/(.*) /wp-content/themes/mytheme/assets/img/$1 [QSA,L]
RewriteRule ^plugins/(.*) /wp-content/plugins/$1 [QSA,L]
#For the spanish language, redirect to the spanish translation
RewriteCond %{HTTP:Accept-Language} ^es [NC]
RewriteCond %{REQUEST_URI} !es [NC]
RewriteRule .? /es%{REQUEST_URI} [L,R=301]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
</IfModule>
# END WordPress
答案 0 :(得分:1)
试试这个:
RewriteEngine on
#For the spanish language, redirect to the spanish translation
RewriteCond %{HTTP:Accept-Language} ^es [NC]
RewriteCond %{REQUEST_URI} !es [NC]
RewriteRule .? %{REQUEST_URI}es/ [L,R=301]