简体   繁体   中英

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.

Installed Wordpress and put up a few test posts which work fine. Installed link juice keeper, which is handling all the 404s fine.

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:

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.

I was able to fix this by switching the permalink structure to default and then back to post name again, and deleting the .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]

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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