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.
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 ??
i believe that gives 302 response... im not sure where ive seen that before, probly experimenting on my site.
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.
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.
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.
The 302 is dangerous to use even on your own domains, or within your site as long as Google ignores this: http://clsc.net/research/google-302-page-hijack.htm Help stop this: http://www.darrinward.com/google302/
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?
If you are trying to setup multiple websites on one server, read what J.D. says above about editting your conf file.
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.