简体   繁体   English

无需语言代码即可重定向来自域的所有流量

[英]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.

相关问题 将所有流量从一个域重定向到另一个域 - Redirect all traffic from one domain to another 将所有流量从子域重定向到新域 - redirect all traffic from just the sub domain to new domain 将所有流量从外部域重定向到本地域主页? - Redirect all traffic to from external domain to local domain homepage? 使用htaccess将所有流量从子域重定向到域,而无需维护目录结构 - Use htaccess to redirect all traffic from subdomain to domain without maintaining directory structure 添加 301 重定向以将所有流量从一个域重定向到另一个域 - Add a 301 redirect to redirect all traffic from one domain to another domain 将所有流量重定向到另一个域的根 - Redirect all traffic to root of another domain 如何使用.htaccess文件将所有流量从一个域重定向到另一个域? - How can I redirect all traffic from one domain to another with an .htaccess file? 将流量重定向到具有端口号的域,而不在URL中显示端口号 - Redirect traffic to a domain with a port number without showing the port number in the URL 301将.htaccess的所有流量重定向到特定的域和uri - 301 redirect .htaccess all traffic to specific domain and uri htaccess-将所有流量重定向到保留页面(开发域除外) - htaccess - redirect all traffic to a holding page, except for the dev domain
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM