2016-03-23 14 views
1

Ich habe die folgende URL-Struktur: www.domain.com/test/anyStringalle Unter URLs in index.php

Ich möchte, dass alle Anforderungen von www.domain.com/test auf eine andere Website umgeleitet werden. Aber nur diejenigen, die ihre Anfrage haben/testen.

Ich konnte eine Umleitung mit www.domain.com aber nicht mit irgendeinem Unterverzeichnis durchführen. Mein Code so weit:

//if our domain is called 
if ($_SERVER['HTTP_HOST'] != "www.domain.com"){ 
header("HTTP/1.1 301 Moved Permanently"); 
$iPod = stripos($_SERVER['HTTP_USER_AGENT'],"iPod"); 
$iPhone = stripos($_SERVER['HTTP_USER_AGENT'],"iPhone"); 
$iPad = stripos($_SERVER['HTTP_USER_AGENT'],"iPad"); 
$Android = stripos($_SERVER['HTTP_USER_AGENT'],"Android"); 
//$webOS = stripos($_SERVER['HTTP_USER_AGENT'],"webOS"); 

//do something with this information 
if($iPod || $iPhone){ 
//browser reported as an iPhone/iPod touch -- do something here 
header("Location: https://itunes.apple.com/de"); exit; 
}else if($iPad){ 
//browser reported as an iPad -- do something here 
header("Location: https://itunes.apple.com/de"); exit; 
}else if($Android){ 
//browser reported as an Android device -- do something here 
header("Location: http://play.google.com/"); exit; 
}else{ 
header("Location: http://www.google.de"); exit; 
} 
} 

Aber das funktioniert nur für den kompletten Host.

+0

Ich wechselte zum Erstellen einer .htaccess-Datei. Siehe unten. Funktioniert perfekt für. – JanScott

Antwort

0

Hm ich testete ein wenig herum:

RewriteEngine on 
RewriteCond %{HTTP_USER_AGENT} "iphone|ipod|ipad" [NC] 
RewriteRule ^(.*)test(.*)$ http://www.apple.com [R=301,L] 

#redirect to android market 
RewriteCond %{HTTP_USER_AGENT} "android" [NC] 
RewriteRule ^(.*)test(.*)$ https://play.google.com [R=301,L]