iSenne
iSenne

Reputation: 2715

Redirect subdomain to different locations based on url

I have a website on a domain that I want to move to another domain. Here is my problem. The root URL has to redirect to a different location on the new domain. Example:

http://subdomain.olddomain.com/ must redirect to http://www.newdomain.com/location

http://subdomain.olddomain.com/code/slug must redirect to http://www.newdomain.com/slug

The htaccess code that I have doesn't work ver

RewriteRule ^/?(.*) http://www.newdomain.com/$1 [R=302,L]

This code works for the second example, but nog on the first. Can anyone help me setup the correct htaccess code?

Upvotes: 0

Views: 35

Answers (1)

Jon Lin
Jon Lin

Reputation: 143876

Try:

RewriteEngine On

RewriteCond %{HTTP_HOST} ^subdomain\.olddomain\.com$ [NC]
RewriteRule ^code/(.*)$ http://www.newdomain.com/$1 [L,R]

RewriteCond %{HTTP_HOST} ^subdomain\.olddomain\.com$ [NC]
RewriteRule ^$ http://www.newdomain.com/location [L,R]

Upvotes: 1

Related Questions