简体   繁体   English

子域301通过.htaccess重定向的问题

[英]Problems with subdomain 301 redirect via .htaccess

Acquired a new domain and trying to get everything pointing back to the main page so I can build from there. 获得了一个新域,并尝试使所有内容都指向主页,以便我可以从那里进行构建。 It has 1 subdomain (that I know of) that I want pointing back to the main page as well. 它也有1个我要指向主页的子域(我知道)。

Installed Wordpress and put up a few test posts which work fine. 安装了Wordpress,并放置了一些工作正常的测试帖子。 Installed link juice keeper, which is handling all the 404s fine. 安装了链接果汁管理器,可以很好地处理所有404。

Put up the following .htaccess intending to take care of the known subdomain as well as links pointing to any I'm not aware of: 设置以下旨在照顾已知子域的.htaccess以及指向我不知道的任何子链接的链接:

RewriteEngine On
RewriteBase /
RewriteCond %{HTTP_HOST} !^example.com$ [NC]
RewriteRule ^(.*)$ http://example.com/$1 [L,R=301]

But it not only doesn't redirect the subdomain (it just gives a This webpage is not available), but it causes the other redirects and posts to quit working. 但这不仅不会重定向子域(它仅给出“此网页不可用”),还会导致其他重定向和帖子退出工作。

Testing URLs that don't exist just gives a standard 404 page, and links from the main page to the existing posts go to the same 404. 测试不存在的URL只会提供一个标准的404页面,并且从主页到现有帖子的链接将转到相同的404。

I was able to fix this by switching the permalink structure to default and then back to post name again, and deleting the .htaccess. 我可以通过将永久链接结构切换为默认设置,然后再次返回到发布名称,并删除.htaccess来解决此问题。

I assume it's my code, but what is wrong with it, what do I need to change, and how do I get the subdomain(s) included in the redirection? 我假设这是我的代码,但是它有什么问题,我需要更改什么,以及如何获得重定向中包含的子域?

Use this. 用这个。

RewriteEngine On
RewriteBase /
RewriteCond %{HTTP_HOST} !^http://www.example.com$ [NC]
RewriteRule ^(.*)$ http://www.subdomain.example.com/ [L,R=301]

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

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