使用.htaccess与动态文​​件夹 - wordpress

时间:2014-10-24 19:20:00

标签: wordpress apache .htaccess mod-rewrite

我在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 /

注意:

  1. 我不能将.htaccess放在所有子文件夹中 - 它们是动态生成的。 (或者我不知道怎么做)
  2. 我已经尝试将这些设置放在/etc/apache2/apache2.conf中。它仍然无济于事。
  3. 我需要避免无限循环
  4. 我如何实现这一目标?

    在第一个答案之后,这是完整的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
    

1 个答案:

答案 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]