Nixon
Nixon

Reputation: 93

htaccess redirect from subdomain to ip

I have an alias like *.domain.com to domain.com.

So, I need to do a redirect from a.domain.com to a specific IP and on the other sub domain like b.domain.com or z.domain.com send error 404.

I understand that it is necessary to dig into .htaccess but can not find the right solution.

Upvotes: 1

Views: 3238

Answers (2)

Nixon
Nixon

Reputation: 93

I find the solution.

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

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

Upvotes: 2

CrazyCasta
CrazyCasta

Reputation: 28302

Ideally you would fix the name server to point a.domain.com to the proper server. If not, you should use virtual hosting and then use a redirect (http://httpd.apache.org/docs/2.2/mod/mod_alias.html#redirect) to get you the right address.

Upvotes: 0

Related Questions