[英]Redirect all traffic from domain without language code
I'm searching for a way to redirect all traffic to the root domain without a language code to a fixed domain with a language code.我正在寻找一种方法,将所有流量重定向到没有语言代码的根域到具有语言代码的固定域。
For example:例如:
www.example.com should redirect to www.example.com/nl www.example.com 应该重定向到 www.example.com/nl
www.example.com/subpage should redirect to www.example.com/nl www.example.com/subpage 应该重定向到 www.example.com/nl
www.example.com/nl = ok www.example.com/nl = 好的
www.example.com/nl/subpage = ok www.example.com/nl/subpage = 好的
etc ...等等 ...
Can someone help me with this RewriteMatch?有人可以帮我解决这个 RewriteMatch 吗?
Please use the following in your /.htaccess
file:请在您的
/.htaccess
文件中使用以下内容:
RewriteCond ${REQUEST_URI} !^/nl(/.*)? [NC]
RewriteRule ^ /nl%2 [R=302,L]
This will redirect as you have described - all request URIs that do not begin with nl
language code will be redirected to include the language code.这将按照您的描述进行重定向 - 所有不以
nl
语言代码开头的请求 URI 都将被重定向以包含语言代码。
However, I have made one assumption: that you would like to redirect /subpage
to /nl/subpage
, which was implied by your statement that /nl/subpage
is 'okay'.但是,我做出了一个假设:您想将
/subpage
重定向到/nl/subpage
,您的声明暗示/nl/subpage
是“好的”。 If this is not the case, please update your question to be more specific.如果不是这种情况,请更新您的问题以使其更具体。
If you are happy with the redirect, you may change 302
to 301
to make the redirect cached by browsers and search engines.如果您对重定向感到满意,可以将
302
更改为301
以使浏览器和搜索引擎缓存重定向。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.