DotDragnet
May 23, 2012, 10:39:40 PM *
Welcome, Guest. Please login or register.

Login with username, password and session length
News: follow us on twitter @dotdragnet
 
   Home   Help Search Login Register  
Pages: [1]   Go Down
  Print  
Author Topic: Redirect sub-domain to main domain.. depending on URL  (Read 371 times)
Ben
Hero Member
*****
Posts: 766


I didn't do it


View Profile Awards
« on: February 06, 2011, 10:39:46 AM »

I've got a client's site that has it's own domain but "lives" at a sub-domain of my portfolio site, Google has helpfully started showing both top & sub domains - so I need to 'bounce' people away from the sub-domain (Google included) if they have come visiting sub.domain.com/whatever and only show if they visit the main domain name.

I don't think the usual 301 request would work?

Hopefully that makes a bit of sense..?  biggrin
Logged
sarahA
DDN Contribs
Hero Member
*****
Posts: 2184



View Profile WWW Awards
« Reply #1 on: February 06, 2011, 11:09:53 AM »

I think this should work. Put it in the htaccess in the root folder for your sub domain or possibly in the directory for the website (sorry, a bit out of touch with code these days!)

Code:
Options +FollowSymlinks
RewriteEngine On
RewriteBase /

#redirect whatever directory to the add-on domain
RewriteCond %{HTTP_HOST} ^sub.domain.com/whatever/? [NC]
RewriteRule ^(.*)$ http://www.correct-domain.co.uk/$1 [R=301,L]

Note, you only need the top part if you don't already have it in the htaccess file.
« Last Edit: February 06, 2011, 11:15:15 AM by sarahA » Logged

JasonD
Global Moderator
Hero Member
*****
Posts: 551



View Profile Awards
« Reply #2 on: February 06, 2011, 01:32:18 PM »

RewriteCond %{HTTP_HOST} ^sub.domain.com$ [NC]

No path in HTTP_HOST.
Logged
Pages: [1]   Go Up
  Print  
 
Jump to:  

Powered by MySQL Powered by PHP Powered by SMF | SMF © 2006-2008, Simple Machines Valid XHTML 1.0! Valid CSS!