Symptom: Client would like to redirect their main site to a subdomain under it. Using the redirect tool in the control panel to send the main domain's index to the subdomain results in all traffic to the site's files redirecting to the subdomain (this is normal behavior using this tool).
Resolution: Place the following code in a .htaccess under the public_html of the site:
RewriteEngine on
RewriteCond %{HTTP_HOST} ^www.domain.com$ [OR]
RewriteCond %{HTTP_HOST} ^domain.com$
RewriteRule ^(.*)$ http://sub.domain.com/ [R=301,L]
The code above will redirect all trafic for www.domain.com and domain.com to the subdomain, while allowing other areas of the site, including other subdomains, to be available normally.
- 3 Utenti hanno trovato utile questa risposta