如何使用 htaccess 将域重定向到子域? [英] How do I redirect domain to subdomain using htaccess?
问题描述
.htaccess 对我来说有点新!
.htaccess is a bit new to me!
我在 www.domain.com 上有一个当前站点,我正在 new.domain.com 上建立一个新站点.
I have a current site located at www.domain.com and I'm building a new site at new.domain.com.
新站点完成后,我想将所有流量重定向到新的子域.
When the new site is finished, I want to re-direct all traffic to the new subdomain.
另外,我想同时解决 url 规范化问题.
Also, I want to resolve url canonicalization at the same time.
任何帮助表示赞赏!谢谢标记
Any help appreciated! Thanks Mark
推荐答案
有几种不同的解决方案.从 SEO 和用户的角度来看,最好的方法是一对一的 301 重定向.它保留了您的链接汁,同时将客户重定向到新网站上的确切位置.
There are several different solutions. The best one, both from SEO and User perspective, is the one-to-one 301 redirect. It preserves your link juice and at the same time redirects the client to the exact location on the new website.
如果你启用了 mod_alias,我会建议一个简单的
If you have mod_alias enabled, I would suggest a simple
RedirectMatch 301 ^(.*)$ / http://new.domain.com/$1
结果指令可以用
RewriteEngine On
RewriteRule (.*) http://new.domain.com/$1 [R=301,L]
如果您需要链接多个条件和过滤器,则第二个是最佳选择.例如,如果您只需要根据用户代理标头重定向某些主机或客户端.
The second one is the best choice if you need to chain multiple conditions and filters. For example, if you need to redirect only certain hosts or clients depending on User Agent header.
记住:mod_redirect 优先于 mod_alias.
Remember: mod_redirect takes precedence over mod_alias.
这篇关于如何使用 htaccess 将域重定向到子域?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!