Reputation: 18544
I need to perform a 301-redirect from a homepage, but without redirecting my subdomains.
Example:
http://info.org => http://newpage.org
http://www.info.org => http://newpage.org
http://subdomain.info.org => http://subdomain.info.org
My current htaccess already includes a 301-redirect from www to non-www:
RewriteEngine on
RewriteCond %{HTTP_HOST} ^www.info.org [NC]
RewriteRule ^(.*)$ http://info.org/$1 [L,R=301,NC]
My question:
How can I redirect my Page with a 301-redirect as described in the example above?
Upvotes: 2
Views: 907
Reputation: 786081
Replace your rule with this rule:
RewriteEngine on
RewriteCond %{HTTP_HOST} ^(www\.)?info\.org$ [NC]
RewriteRule !^test(/.*)?$ http://newpage.org%{REQUEST_URI} [L,R=301,NC]
This will redirect:
http://info.org => http://newpage.org
http://www.info.org => http://newpage.org
But http://info.org/test
OR http://subdomain.info.org
will remain unaffected.
Make sure to clear your browser cache before testing this.
Upvotes: 2