1. Advertising
    y u no do it?

    Advertising (learn more)

    Advertise virtually anything here, with CPM banner ads, CPM email ads and CPC contextual links. You can target relevant areas of the site and show ads based on geographical location of the user if you wish.

    Starts at just $1 per CPM or $0.10 per CPC.

How to cheat web hosting....

Discussion in 'PHP' started by nfd2005, May 24, 2005.

  1. #1
    Hey all,

    I've decided to change my web host cheating post to something actually useful.

    I'm sure that most of you know about this....

    To redirect traffic to a specific domain, for example if you have a domain listed on the engines, but parked under a different domain, then here's what you can do:

    
    if (($_SERVER['HTTP_HOST'] == 'www.domain.com') OR ($_SERVER['HTTP_HOST'] == 'domain.com')) {
    	header("Location: http://www.otherdomain.com/");
    	exit;
    }
    
    Code (markup):
    Basically it says that if someone goes to your old address: www.domain.com they are redirected with the new address. It really beats using the meta refresh...

    Thanks for reading.
     
    nfd2005, May 24, 2005 IP
    SEbasic likes this.
  2. jlawrence

    jlawrence Peon

    Messages:
    1,368
    Likes Received:
    81
    Best Answers:
    0
    Trophy Points:
    0
    #2
    What response code will the above give. It should give a 200 response, since your not changing the response code. Oooops, you've now broken the http standard. A 200 response with a different location ?

    If you're going to do something like this, then please have some sense. Read up on the rest of the http headers.
    Location is only one of the headers. What sort of redirect is the above giving ??
    Who know's since you've not bothered to specify it in the header, the header will/should still contain a 200 reply header. If you're specifiying a diferent location, then please have the decency to set the correct code (301, 302 or whatever)
    If you're going to start rewriting the headers manually, then please read up on what they all are and what they do.
    One useful header which can be rewritten is the last-modified: header. You could dynamically rewrite this one so that anything that calls the page thinks it was last changed on what ever day you want.
    Also be aware that some headers require a \r\n end of line marker.

    Before you start messing around with protocol fields, it would be better to go away and read up on what they do.
    for http 1.0 see RFC1945, for http 1.1 read RFC2616 (both available at www.rfc-editor.org).

    If you're determined to manually rewrite headers, then learn what you're doing. If you get some strange effects in the SE's then it's your own problem.

    Here's a question on the above offering:
    What would a SE bot record if it goes to a url, gets a 200 response code and at the same time gets a location: that is different to where it thinks it is ??
     
    jlawrence, May 25, 2005 IP
    nfd2005 likes this.
  3. Stin

    Stin Guest

    Messages:
    264
    Likes Received:
    9
    Best Answers:
    0
    Trophy Points:
    0
    #3
    i believe that gives 302 response... im not sure where ive seen that before, probly experimenting on my site.
     
    Stin, May 25, 2005 IP
  4. SEbasic

    SEbasic Peon

    Messages:
    6,317
    Likes Received:
    318
    Best Answers:
    0
    Trophy Points:
    0
    #4
    SEbasic, May 25, 2005 IP
    nfd2005 likes this.
  5. jlawrence

    jlawrence Peon

    Messages:
    1,368
    Likes Received:
    81
    Best Answers:
    0
    Trophy Points:
    0
    #5
    I'm going to have to try this. I'm not convinced that the webserver will send back a 302. It should send a 200 as you've manually changed the location: header without changing the reply code.

    I'll post my findings later.
     
    jlawrence, May 25, 2005 IP
  6. jlawrence

    jlawrence Peon

    Messages:
    1,368
    Likes Received:
    81
    Best Answers:
    0
    Trophy Points:
    0
    #6
    Answer: Yes it gives a 302 response.
    Yuck. That makes the first posting bad advise.
    your need to write a reply: header as well specifying a 301 response.
     
    jlawrence, May 25, 2005 IP
  7. J.D.

    J.D. Peon

    Messages:
    1,198
    Likes Received:
    65
    Best Answers:
    0
    Trophy Points:
    0
    #7
    If you have access to the main config file, it's better to set up a virtual website instead:

    NameVirtualHost *:80

    <VirtualHost *:80>
    ServerName www. domain.com
    Redirect / www. newdomain.com
    </VirtualHost>

    The fact that crooks use 302 as a tool for their purposes doesn't make 302 a "bad" return code. 302 has its purpose and if you want to redirect temporarily one of *your* websites to another one of *your* locations, 302 is the code to use. New redirection status codes 303 and 307 have been added to the latest HTTP spec to make it clear which form of redirection to use.

    J.D.
     
    J.D., May 25, 2005 IP
  8. NetMidWest

    NetMidWest Peon

    Messages:
    1,677
    Likes Received:
    151
    Best Answers:
    0
    Trophy Points:
    0
    #8
    NetMidWest, May 25, 2005 IP
    nfd2005 likes this.
  9. nfd2005

    nfd2005 Well-Known Member

    Messages:
    295
    Likes Received:
    20
    Best Answers:
    0
    Trophy Points:
    130
    #9
    Sorry guys,

    just thought it may be useful info...
    geez..

    So what would be the best solution... if I may ask without getting my head ripped off?

    Meta refresh?
    HTACCESS?
    Other?

    I've researched and found this:
    header("HTTP/1.1 301 Moved Permanently");
    Code (markup):
    Is this an acceptable addon to my header code above or am I still in the wrong place?
     
    nfd2005, May 25, 2005 IP
  10. Stin

    Stin Guest

    Messages:
    264
    Likes Received:
    9
    Best Answers:
    0
    Trophy Points:
    0
    #10
    If you are trying to setup multiple websites on one server, read what J.D. says above about editting your conf file.
     
    Stin, May 25, 2005 IP
  11. nfd2005

    nfd2005 Well-Known Member

    Messages:
    295
    Likes Received:
    20
    Best Answers:
    0
    Trophy Points:
    130
    #11
    Well I don't have access to the conf file....
     
    nfd2005, May 25, 2005 IP
  12. J.D.

    J.D. Peon

    Messages:
    1,198
    Likes Received:
    65
    Best Answers:
    0
    Trophy Points:
    0
    #12
    Local .htaccess file will work as well (although somewhat slower than using the global config file). Use whatever response code that works for you - as long as you point to your own content, there's nothing wrong with using 302's. Just add Redirect to your .htaccess file - that's all you need. Here's more info on this:

    http://httpd.apache.org/docs-2.0/mod/mod_alias.html#redirect

    J.D.
     
    J.D., May 25, 2005 IP