Using mod_rewrite and .htaccess

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.

  • 0 Користувачі, які знайшли це корисним
Ця відповідь Вам допомогла?

Схожі статті

Can you map my domain/a subdomain to a typepad blog/photo album?

Domains or subdomains can be mapped to blogs or photo albums (or other materials) hosted at...

HOW TO: Combat referer spam/block certain referers

Symptom: A client wishes to deny access to their site (or parts of it) when the traffic is...

HOW TO: Block entire countries from your site

Symptom: A client wishes to block all visitors from a particular country to their site. Can this...

My phpBB forum installation is not accessible

Symptom: Client cannot access phpBB forum installation. Permissions on the forum installation...

What nameservers should be used for my account?

For servers in the Greek series, the following nameservers should be used:ns.hmdnsgroup.com -...