Forum Moderators: phranque

Message Too Old, No Replies

recirect done in php to page match

wish to apply to some pages only

         

nippi

4:16 am on Jun 27, 2011 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



I wish to redirect some pages on my domain to 2nd domain, but only for Opera.

I can do this to the following.

<?php
if (strstr($_SERVER['HTTP_USER_AGENT'], "Opera")) {
header("HTTP/1.1 301 Moved Permanently");
header("Location: [domainname.com...]
exit;
}
else {
header('Content-Type: text/html; charset=ISO-8859-1');
};
?>

But would prefer to redirect to the same url on the other domain.

I can;t make an htaccess rule, as there are too many pages i wish to exclude from the rule, this bit of php being inserted as necessary into the affected pages.

How do a modify this to transfer to the matching url, rather than the root of the 2nd domain?

g1smd

8:03 am on Jun 27, 2011 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



You'll need to detect the requested path and file, and add that back on to the end of the 'location'.

Don't forget that if the request is for the index file to not include the filename in the redirect URL, just end with a trailing slash.