How do I redirect an alias domain to an internal folder, another address, or my SSL domain?

Add any of the code below to an .htaccess file in the "docs" folder within your web site. i.e.



Redirect to a subdirectory:

RewriteEngine on
Options +FollowSymlinks

RewriteCond %{HTTP_HOST} ^(www\.)?example\.com
RewriteCond %{REQUEST_URI} !/test/
RewriteRule (.*) /test/$1 [L]

Redirect one domain to another domain, optionally adding a subdirectory (i.e. wordpress/)

This is useful if they want to redirect all domain traffic to some other location, but still want to access the server by IP address, or another hostname such as * subdomain. The simpler methods below don't care what the current hostname is, they will redirect all traffic.

RewriteCond %{HTTP_HOST} ^$ [NC]
RewriteRule ^(.*)$$1 [R=302,L]

The "$1" in the rewrite rule will be replaces by whatever parameters were in the URL after, so that data will get passed to the destination. The "^" indicates we don't give a hoot whether http or https is being used initially. 302 indicates a temporary redirect. Don't use permanent (301) unless this really is likely to be permanent. Has to do with search engine ranking.

Redirect ALL traffic temporarily to another URL:

Redirect 302 /

Redirect ALL traffic to SSL version of your site:

RewriteEngine On
RewriteCond %{SERVER_PORT} 80
RewriteRule ^(.*)$$1 [R=301,L]

Redirect ALL traffic EXCEPT particular subdomain(s) to another URL:

RewriteEngine On
# Redirect anything except,
RewriteCond %{HTTP_HOST} !^(foo|bar)$ [NC]
# Redirect to, preserving the URI
RewriteRule ^(.*)$$1 [R=302,L]

For redirecting ALL traffic permanently to another URL:

Redirect 301 /

Redirecting a specific file to another location

Redirect /index.html

Records in this category

Sticky FAQs