【发布时间】:2014-10-24 19:19:59
【问题描述】:
我的 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/
注意:
- 我无法将 .htaccess 放入所有子文件夹 - 它们是动态生成的。 (或者我不知道怎么做)
- 我已尝试将这些设置放在 /etc/apache2/apache2.conf 的 .它仍然没有帮助。
- 我需要避免无限循环
我该如何做到这一点?
这是完整的 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
【问题讨论】:
-
^$不允许www.mysite.com/之后的任何内容
标签: wordpress apache .htaccess mod-rewrite