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.

  • 3 användare blev hjälpta av detta svar
Hjälpte svaret dig?

Relaterade artiklar

PHP script error: FATAL ERROR: register_globals is disabled in php.ini, please enable it!

<b>Symptom: </b>The following error appears on a site running a php-based...

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...

Expression Engine installation generates "variable references" error

Symptom: Expression Engine installations older than version 1.3.1 generate an "Only variable...

My phpBB forum installation is not accessible

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

Enabling register_globals

Symptom: A client's script requires that register_globals be enabled.Resolution: Globals are not...