How to use .htacces to disallow external links?

Discussion in 'Site & Server Administration' started by whosedomain, Aug 20, 2009.

  1. #1
    for examples, my domain is abc.com, how can i use .htaccess to disallow any other external links in my site, say if there is an external domain: 123.com.

    How can i let 123.com becomes my domain abc.com or something else?

    tks.
     
    whosedomain, Aug 20, 2009 IP
  2. premiumscripts

    premiumscripts Peon

    Messages:
    1,062
    Likes Received:
    48
    Best Answers:
    0
    Trophy Points:
    0
    #2
    Htaccess can't do this for you. htaccess is a request preprocessor, not a post processor.
     
    premiumscripts, Aug 20, 2009 IP
  3. whosedomain

    whosedomain Active Member

    Messages:
    257
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    55
    #3
    how to use .htaccess to let abc.com become 123.comthen?
     
    whosedomain, Aug 22, 2009 IP
  4. premiumscripts

    premiumscripts Peon

    Messages:
    1,062
    Likes Received:
    48
    Best Answers:
    0
    Trophy Points:
    0
    #4
    You could do somehing like :

    RewriteCond %{HTTP_HOST} ^www.olddomain.com$[OR]
    RewriteCond %{HTTP_HOST} ^olddomain.com$
    RewriteRule ^(.*)$ http://www.newdomain.com/$1 [R=301,L] 
    Code (markup):
    or

    
    redirect 301 / http://www.newdomain.com 
    
    Code (markup):
    But all these only work if you own olddomain.com (abc.com). You cannot rewrite urls that you do not own because your htaccess needs to be on that domain.
     
    premiumscripts, Aug 22, 2009 IP
  5. kailash

    kailash Well-Known Member

    Messages:
    1,248
    Likes Received:
    42
    Best Answers:
    0
    Trophy Points:
    190
    #5
    You have to do this via scripting (PHP) rather than .htaccess.
     
    kailash, Aug 23, 2009 IP
  6. whosedomain

    whosedomain Active Member

    Messages:
    257
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    55
    #6
    how to do via php, please?
     
    whosedomain, Aug 23, 2009 IP
  7. kailash

    kailash Well-Known Member

    Messages:
    1,248
    Likes Received:
    42
    Best Answers:
    0
    Trophy Points:
    190
    #7
    I am not good in programming otherwise I provide sample code :)
     
    kailash, Aug 28, 2009 IP