Reputation: 602
Basically I want sub.domain.com to redirect to domain.com, but only that url. For example sub.domain.com/page should still load without redirecting. How can I do this .htaccess?
Upvotes: 2
Views: 531
Reputation: 1
# subdomain home page to main domain page
RewriteEngine on
RewriteBase /
RewriteCond %{HTTP_HOST} ^subdomain\.example\.com$ [NC]
RewriteCond %{REQUEST_URI} ^/?$
RewriteRule .* https://www.example.com [L,R=301]
This works for me as I wanted to have 301 redirect and to https main domain page. I hope this helps. Thanks..
Upvotes: 0
Reputation: 51711
Your .htaccess should look like
RewriteEngine on
RewriteBase /
RewriteCond %{HTTP_HOST} ^sub\.domain\.com$ [NC]
RewriteCond %{REQUEST_URI} ^/?$
RewriteRule .* http://domain.com [R,L]
Upvotes: 3
Reputation: 13344
This should work within .htaccess
placed in the root directory. The empty rule (nothing between ^$
) is interpreted as /
(the root). Your subpages and subdirectories should remain unaffected. Requires mod_rewrite.
RewriteEngine on
RewriteRule ^$ http://new.domain.com/ [L]
Upvotes: 0