简体   繁体   English

.htaccess 301 将主页重定向到子域

[英].htaccess 301 redirect Homepage to subdomain

I would like to redirect my home page to a subdomain in .htaccess.我想将我的主页重定向到 .htaccess 中的子域。 Ive tried several different ways I found online.我尝试了几种我在网上找到的不同方法。 None have worked.没有一个工作。

https://example.com/index.com to https://sub.example.com/index.com https://example.com/index.comhttps://sub.example.com/index.com

Assuming that you actually want to redirect all requests to that subdomain this probably is what you are looking for:假设您实际上想要将所有请求重定向到该子域,这可能就是您要查找的内容:

RewriteEngine on 
RewriteCond %{HTTP_HOST} ^(www\.)?example\.com$
RewriteRule ^ https://sub.example.com%{REQUEST_URI} [R=301,L]

It probably makes sense to start using R=302 temporary redirections first.首先开始使用 R=302临时重定向可能是有意义的。 And to only change those to R=301 permanent redirections once everything works as desired.并且只有在一切按预期工作时才将它们更改为 R=301永久重定向。 That prevents nasty caching issues on the client side.这可以防止客户端出现令人讨厌的缓存问题。 Also you always want to test using a fresh anonymous browser window.此外,您总是希望使用新的匿名浏览器窗口进行测试。

Best place to implement such rules is in the central http server's host configuration.实施此类规则的最佳位置是中央 http 服务器的主机配置。 If you do not have access to that you can use a distributed configuration file instead (".htaccess"), if you have enabled the consideration of such files in the http server ... Above rules will work likewise if that file is placed inside the DOCUMENT_ROOT folder of the http host.如果您无权访问,则可以使用分布式配置文件(“.htaccess”),如果您已在 http 服务器中启用了对此类文件的考虑...如果将该文件放在其中,上述规则同样适用http 主机的DOCUMENT_ROOT文件夹。

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

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