简体   繁体   English

htaccess重定向语言文件夹

[英]htaccess redirect language folder

I'd like to redirect all incoming requests in a .htaccess file that match the following ruleset. 我想重定向.htaccess文件中与以下规则集匹配的所有传入请求。

domain.com -> www.domain.com/en (en is default language)

domain.com/foo -> www.domain.com/en/foo

domain.com/foo?bar=baz -> www.domain.com/en/foo?bar=baz

www.domain.com -> www.domain.com/en
...

If a request contains a language parameter from a given list (en|fr|de) there should be no redirect to 'en'. 如果请求包含给定列表(en | fr | de)中的language参数,则不应重定向到“ en”。

Example: 例:

domain.com/de/foo/whatever?bar=baz -> www.domain.com/de/foo/whatever?bar=baz

What I have so far is just the redirect from domain.com to www.domain.com 到目前为止,我只是从domain.com重定向到www.domain.com

RewriteCond %{HTTP_HOST} !^www\..* [NC]
RewriteRule ^(.*) http://www.%{HTTP_HOST}/$1 [R=301,L]

I really hope someone can help. 我真的希望有人能提供帮助。 Thanks. 谢谢。

RewriteCond %{REQUEST_URI} !^/(en|fr|de) [NC]
RewriteRule ^(.*)$ /en/$1 [R=301,L,QSA]

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM