Reputation: 295
I have the following URL structure: www.domain.com/test/anyString
I want that all requests of www.domain.com/test are redirected to another site. But only these who have /test/ in their request.
I was able to perform a redirect with www.domain.com but not with any subdirectory. My code so far:
//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;
}
}
But this only works for the complete host.
Upvotes: 1
Views: 100
Reputation: 295
Hm i tested a little bit around:
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]
Upvotes: 0
Reputation: 1213
Use apache rewrite engine, With out writing any PHP code, you can do it. Please click below link for the same
https://httpd.apache.org/docs/2.4/rewrite/remapping.html
For eg:
RewriteEngine on
RewriteRule "^/text" "/someurl" [R]
Upvotes: 1