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.

 docs/.htaccess

 

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 *.brownrice.com subdomain. The simpler methods below don't care what the current hostname is, they will redirect all traffic.

RewriteCond %{HTTP_HOST} ^www.example.com$ [NC]
RewriteRule ^(.*)$ http://www.someotherplace.com/optional-path/$1 [R=302,L]

The "$1" in the rewrite rule will be replaces by whatever parameters were in the URL after example.com/, 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 / http://www.example.com

Redirect ALL traffic to SSL version of your site:

RewriteEngine On
RewriteCond %{SERVER_PORT} 80
RewriteRule ^(.*)$ https://www.example.com/$1 [R=301,L]

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

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

For redirecting ALL traffic permanently to another URL:

Redirect 301 / http://www.example.com/

Redirecting a specific file to another location

Redirect /index.html http://example.com/newdirectory/

You cannot comment on this entry