{"id":276,"date":"2017-05-17T15:21:45","date_gmt":"2017-05-17T15:21:45","guid":{"rendered":"https:\/\/www.web-workers.ch\/?p=276"},"modified":"2017-05-18T08:16:23","modified_gmt":"2017-05-18T08:16:23","slug":"php-redirect-to-a-domain-if-the-called-domain-is-equal-to-another-domain","status":"publish","type":"post","link":"https:\/\/www.web-workers.ch\/index.php\/2017\/05\/17\/php-redirect-to-a-domain-if-the-called-domain-is-equal-to-another-domain\/","title":{"rendered":"PHP redirect to a domain if the called domain is equal to another domain"},"content":{"rendered":"<p>Question: Is it possible to redirect a user opening a domain to a different domain through the use of PHP?<br \/>\nSay the user goes to www.domainA.com and I want to redirect them to www.domainB.com, how would I do so without the use of a meta refresh? Possible?<\/p>\n<p>Answer:<br \/>\n<code>$host <span style=\"color: #ff0000;\">=<\/span> $_SERVER[<span style=\"color: #ffff99;\">'HTTP_HOST'<\/span>];<\/code><code>$hosts\u00a0<span style=\"color: #ff0000;\">=\u00a0<span style=\"color: #00ffff;\">a<\/span><\/span><span style=\"color: #00ffff;\">rray<\/span>(<br \/>\n<span style=\"color: #ffff99;\">\u00a0 \u00a0 'roganmedical.com'<\/span> ,<br \/>\n<\/code><code>\u00a0 \u00a0 <span style=\"color: #ffff99;\">'roganmedical.com'<\/span> ,<br \/>\n<span style=\"color: #ffff99;\">\u00a0 \u00a0 'www.roganmedical.com'<\/span> ,<\/code><code>\u00a0 \u00a0 <span style=\"color: #ffff99;\">'http:\/\/roganmedical.com'<\/span> ,<\/code><code>\u00a0 \u00a0 <span style=\"color: #ffff99;\">'http:\/\/www.roganmedical.com'<\/span> ,<\/code><code>\u00a0 \u00a0 <span style=\"color: #ffff99;\">'rogan-medical.ch'<\/span> ,<\/code><code>\u00a0 \u00a0 <span style=\"color: #ffff99;\">'www.rogan-medical.ch'<\/span> ,<\/code><code>\u00a0 \u00a0 <span style=\"color: #ffff99;\">'http:\/\/rogan-medical.ch'<\/span> ,<\/code><code>\u00a0 \u00a0 <span style=\"color: #ffff99;\">'http:\/\/www.rogan-medical.ch'<\/span> ,<\/code><code>\u00a0 \u00a0 <span style=\"color: #ffff99;\">'schmerzen-wastun.ch'<\/span> ,<\/code><code>\u00a0 \u00a0 <span style=\"color: #ffff99;\">'www.schmerzen-wastun.ch'<\/span> ,<\/code><code>\u00a0 \u00a0 <span style=\"color: #ffff99;\">'http:\/\/schmerzen-wastun.ch'<\/span> ,<\/code><code>\u00a0 \u00a0 <span style=\"color: #ffff99;\">'http:\/\/www.schmerzen-wastun.ch'<\/span><\/code><code>\u00a0 \u00a0 );<\/code><code><span style=\"color: #ff0000;\">if<\/span>(<span style=\"color: #00ffff;\">in_array<\/span>($host, $hosts)) {<\/code><code>\u00a0 \u00a0 <span style=\"color: #00ffff;\">header<\/span>(<span style=\"color: #ffff99;\">'Location: http:\/\/www.roganmedical.ch'<\/span>);<\/code><code>}<\/code><\/p>\n","protected":false},"excerpt":{"rendered":"<p>Question: Is it possible to redirect a user opening a domain to a different domain through the use of PHP? Say the user goes to www.domainA.com and I want to [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":286,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"jetpack_post_was_ever_published":false,"_jetpack_newsletter_access":"","_jetpack_dont_email_post_to_subs":false,"_jetpack_newsletter_tier_id":0,"_jetpack_memberships_contains_paywalled_content":false,"_jetpack_memberships_contains_paid_content":false,"footnotes":"","jetpack_publicize_message":"","jetpack_publicize_feature_enabled":true,"jetpack_social_post_already_shared":true,"jetpack_social_options":{"image_generator_settings":{"template":"highway","default_image_id":0,"font":"","enabled":false},"version":2}},"categories":[14],"tags":[63,60,43,41,29],"class_list":["post-276","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-coding","tag-ad","tag-domain","tag-http","tag-php","tag-server"],"jetpack_publicize_connections":[],"jetpack_featured_media_url":"https:\/\/i0.wp.com\/www.web-workers.ch\/wp-content\/uploads\/2017\/05\/php-11.png?fit=800%2C398&ssl=1","jetpack_sharing_enabled":true,"jetpack_shortlink":"https:\/\/wp.me\/p8sxjX-4s","jetpack-related-posts":[],"jetpack_likes_enabled":true,"_links":{"self":[{"href":"https:\/\/www.web-workers.ch\/index.php\/wp-json\/wp\/v2\/posts\/276","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.web-workers.ch\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.web-workers.ch\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.web-workers.ch\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.web-workers.ch\/index.php\/wp-json\/wp\/v2\/comments?post=276"}],"version-history":[{"count":8,"href":"https:\/\/www.web-workers.ch\/index.php\/wp-json\/wp\/v2\/posts\/276\/revisions"}],"predecessor-version":[{"id":288,"href":"https:\/\/www.web-workers.ch\/index.php\/wp-json\/wp\/v2\/posts\/276\/revisions\/288"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/www.web-workers.ch\/index.php\/wp-json\/wp\/v2\/media\/286"}],"wp:attachment":[{"href":"https:\/\/www.web-workers.ch\/index.php\/wp-json\/wp\/v2\/media?parent=276"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.web-workers.ch\/index.php\/wp-json\/wp\/v2\/categories?post=276"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.web-workers.ch\/index.php\/wp-json\/wp\/v2\/tags?post=276"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}