1

I two domains. domainA.co.uk and domainB.co.uk

domainA.co.uk is the main site. this is where all the files are, including the htaccess file

domainB.co.uk is not hosted on the same server, but the DNS A record is pointing to the domainA.co.uk IP address.

Is it possible to redirect domainB.co.uk to domainA.co.uk/page?

Dharman
  • 30,962
  • 25
  • 85
  • 135
magicspon
  • 926
  • 2
  • 9
  • 28

2 Answers2

2

On domainB.co.uk pointing host enable mod_rewrite and .htaccess through httpd.conf and then put this code in your .htaccess under DOCUMENT_ROOT directory:

Options +FollowSymLinks -MultiViews
# Turn mod_rewrite on
RewriteEngine On
RewriteBase /

RewriteCond %{HTTP_HOST} ^(www\.)?domainB\.co\.uk$ [NC]
RewriteRule ^ http://domainA.co.uk%{REQUEST_URI} [R=301,L]
anubhava
  • 761,203
  • 64
  • 569
  • 643
  • +1 from me as well. I swear whenever I use [R=301] I'm told, "but I don't want my url to change." :) – Ravi K Thapliyal Aug 15 '13 at 19:41
  • @RaviThapliyal: Thanks. Yes that is funny :) However in this case domains were different so I guessed `R` is needed here. – anubhava Aug 15 '13 at 19:45
  • @anubhava .. but since domain B's DNS was pointing to domain A's server; I actually thought of this as how hosting companies setup an add-on domain (in the sub-dir of the primary domain). Well, "client is always right!" :) – Ravi K Thapliyal Aug 15 '13 at 19:53
1

Add this to your .htaccess in your web root / directory of domainA.co.uk

RewriteEngine on
RewriteBase /

RewriteCond %{HTTP_HOST} ^(www\.)?domainB\.co\.uk$ [NC]
RewriteCond %{REQUEST_URI} !^/page [NC]
RewriteRule ^(.*)$ page/$1 [L]
Ravi K Thapliyal
  • 51,095
  • 9
  • 76
  • 89
  • Hi, thanks for your reply. It didn't work for me though. The answer below did. Thanks – magicspon Aug 15 '13 at 19:38
  • @magicspon, both the answers are correct. I just did an internal redirect (no [R=301]) because usually people prefer to keep the other domain name showing in the address bar. – Ravi K Thapliyal Aug 15 '13 at 19:48
  • Hello, Just tried it again, this time with Options +FollowSymLinks -MultiViews, but it still doesn't work for me. Thanks – magicspon Aug 15 '13 at 19:54
  • @magicspon, it's okay. If you've already got it working, don't mess around with your setup any more. – Ravi K Thapliyal Aug 15 '13 at 19:56
  • I would prefer to be able to have domainB.co.uk/page as the url. This is what I have at the moment: RewriteCond %{HTTP_HOST} ^(www\.)?hartconstructionanddesign\.co\.uk$ [NC] RewriteRule ^ http://hartdesignandconstruction.co.uk/construction-design%{REQUEST_URI} [R=301,L] – magicspon Aug 15 '13 at 19:59
  • Actually, my code serves `domainB.co.uk/index.php` transparently (without external redirect) from `domainA.co.uk/page/index.php`. So, it's like domainB living out of a sub-dir `/page` of the main domainA. So, going to `domainB.co.uk/page` would give a 404 because the idea is to make the add-on domain appear as another top level domain. – Ravi K Thapliyal Aug 15 '13 at 20:07
  • I think I understand... .htaccess melts my brain a little! thanks anyway ;) – magicspon Aug 15 '13 at 20:15