将.htaccess与动态文件夹一起使用-wordpress

将.htaccess与动态文件夹一起使用-wordpress,wordpress,apache,.htaccess,mod-rewrite,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) u

我在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 
这对于站点的根目录来说工作得很好。e、 g www.mysite.com,如果用户的浏览器语言为西班牙语默认值,它将重定向到www.mysite.com/es/

但是,如果用户单击另一个指向www.mysite.com/help/的链接,则不会加载西班牙语版的帮助页面-预计会自动加载,网址为www.mysite.com/help/es/

注:

  • 我无法将.htaccess放在所有子文件夹中-它们是动态生成的。(或者我不知道怎么做)
  • 我已尝试将这些设置放在中的/etc/apache2/apache2.conf中。这仍然无济于事
  • 我需要避免无限循环
  • 我该如何做到这一点

    这是完整的mod_重写部分,在第一个答案之后

    # 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
    
    #开始WordPress
    重新启动发动机
    重写基/
    重写规则^index\.php$-[L]
    重写规则^assets/css/(.*)/wp content/themes/mytheme/assets/css/$1[QSA,L]
    重写规则^assets/js/(.*)/wp content/themes/mytheme/assets/js/$1[QSA,L]
    重写规则^assets/img/(.*)/wp content/themes/myteme/assets/img/$1[QSA,L]
    重写规则^plugins/(.*)/wp content/plugins/$1[QSA,L]
    #对于西班牙语,重定向到西班牙语翻译
    RewriteCond%{HTTP:Accept Language}^es[NC]
    重写cond%{REQUEST_URI}!es[NC]
    重写规则/es%{REQUEST_URI}[L,R=301]
    重写cond%{REQUEST_FILENAME}-F
    重写cond%{REQUEST_FILENAME}-D
    重写规则/index.php[L]
    #结束WordPress
    
    试试这个:

    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]
    

    ^$
    不允许在
    www.mysite.com/
    之后添加任何内容。这对于www.mysite.com/www.mysite.com/page1、www.mysite.com/page2等链接非常有效。但是,如何处理www.mysite.com/page1/subpage2?此重写规则应适用于作业:
    重写规则。?%{REQUEST_URI}/es[L,R=301]
    只要替换旧的就行了。事实上,谢谢,确实如此。然而,当我使用它时,我注意到一些图像消失了。有没有可能它也在重写一些东西,比如请在wordpress页面属性中标记为具有父级的页面上尝试。使用
    www.mysite.com/page1/subpage2
    进行测试时不会像应该的那样将我发送到
    www.mysite.com/page1/subpage2/es
    。为了使图像不消失,必须使用完整路径,而不是相对路径。