JerryHuang.me
JerryHuang.me

Reputation: 1790

Redirect www to new subdomain

I want to redirect www.acme.com to subdomain.acme.com

What I have so far:

RewriteEngine on
RewriteRule ^http://www.acme.com/(.*)$mysubdomain.acme.com/$1 [R=301,L]

This needs to work for page links with and without 'http://'

Thank you.

EDIT*** adding my complete .htaccess

RewriteEngine on
RewriteBase /
#RewriteRule (.*)\.html $1 [R=301,L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php?q=$1 [L,QSA]

Upvotes: 1

Views: 64

Answers (3)

anubhava
anubhava

Reputation: 785481

Enable mod_rewrite and .htaccess through httpd.conf and then put this code in your DOCUMENT_ROOT/.htaccess file:

RewriteEngine On

RewriteCond %{HTTP_HOST} ^(?:www\.)?(acme\.com)$ [NC]
RewriteRule ^ http://subdomain.%1%{REQUEST_URI} [NE,R=301,L]

This will do permanent redirect of every URI from www.acme.com OR acme.com to subdomain.acme.com.

Upvotes: 2

shawnzhu
shawnzhu

Reputation: 7585

RewriteEngine on
RewriteCond %{HTTP_HOST} ^www.acme.com
RewriteRule ^(.*)$ http://subdomain.acme.com/$1 [L,NC,QSA]

Upvotes: 0

Patrick Tudor
Patrick Tudor

Reputation: 101

Try something like...

RewriteCond %{HTTP_HOST} !^subdomain\.acme\.com [NC]
RewriteCond %{HTTP_HOST}   !^$
RewriteRule ^/(.*)         http://subdomain.acme.com/$1 [L,R=301]

The conditions are: "if the host doesn't match subdomain or is unset." With the acton of: redirect any provided URI to that new Host and preserve the URI.

Upvotes: -1

Related Questions