How do I redirect an alias domain to an internal folder or address?


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

 docs/.htaccess

 

For redirecting locally, like 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.

For redirecting ALL traffic temporarily to another URL:

Redirect 302 / http://mt-example.com/

For redirecting 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://mt-example.com/

Redirecting a specific file to another location

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

Records in this category

Sticky FAQs