Forum Moderators: phranque

Message Too Old, No Replies

Redirect subdomain to it's own domain

         

JMZolezzi

11:16 pm on May 20, 2008 (gmt 0)

10+ Year Member



I know this has been asked plenty of times, but I can't seem to make it.

I'm using the following code extracted from one of one of jdMorgan's post to redirect blog.mydomain.com to www.domain-blog.com:


RewriteEngine On
RewriteCond %{HTTP_HOST} blog\.mydomain\.com
RewriteRule (.*) http://www.domain-blog.com/$1 [R=301,L]

It's seems to work fine except for one small thing. The following redirectios happens:

I'm placing the .htaccess at www.mydomain.com and I kept the following lines at the DNS zone of mydomain.com:

  1. email A entry IP
  2. www.email A entry IP

Where IP is replaced by the actual IP where both, mydomain.com and domain-blog.com are hosted.

Can anyone give me a hand of this please? Can't seem to do the right thing.

[edited by: JMZolezzi at 11:59 pm (utc) on May 20, 2008]

jdMorgan

12:44 am on May 21, 2008 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Your code is essentially correct. This results in the question: "Where is the code on this server that internally rewrites blog.mydomain.com to /blog"?

It's very likely that this code is present. The trick is to get your new redirect code to execute first.

If that's not possible, then the work-around is to put "^blog/" at the start of your RewriteRule pattern, outside of the parenthesized ".*" expression.

Jim