Web forwarding
#1
Scooby Regular
Thread Starter
Join Date: Jul 2001
Location: maturin23 - 205GTi Drivers.com
Posts: 504
Likes: 0
Received 0 Likes
on
0 Posts
Web forwarding
Hi all,
I own both the .com and .co.uk domains for my website, and have up to now run parallel sites (it's static site at this point).
How do I automatically direct people who visit on the .uk domain to the .com site?
I'm sure this is stupidly easy, but all I found on Google were companies asking for money to do this.
cheers
ian
I own both the .com and .co.uk domains for my website, and have up to now run parallel sites (it's static site at this point).
How do I automatically direct people who visit on the .uk domain to the .com site?
I'm sure this is stupidly easy, but all I found on Google were companies asking for money to do this.
cheers
ian
#2
Here are just two simple ways to redirect your page!
1. This first example is useful if you want to inform your visitor that you have moved.
Into the HEAD section of your page type:
<meta http-equiv="refresh" content="5; URL=http://my new web address">
And into the BODY of your document put
"my old web address" has moved to "my new web address"
If your browser does not automatically redirect you in 5 seconds,
click <a href="http://my new web address">here</a> to go to the new site.
2. The second example using java script is handy if you have a number of domain names (for whatever reason) but want all names to point to the same domain.
Just add this to the top of your document:
<script language="JavaScript">
<!--
if( -1 == location.href.
toLowerCase().
indexOf('mydomainA.com') )
{
location.href = 'http://mydomainA.com';
}
// -->
</script>
The above code will check if 'mydomainA.com' is part of the code and if not will immediately redirect to 'http://mydomainA.com'
Option 2 is best I think unless you want to actually inform your visitor of the change then option 1 can be a good idea.
1. This first example is useful if you want to inform your visitor that you have moved.
Into the HEAD section of your page type:
<meta http-equiv="refresh" content="5; URL=http://my new web address">
And into the BODY of your document put
"my old web address" has moved to "my new web address"
If your browser does not automatically redirect you in 5 seconds,
click <a href="http://my new web address">here</a> to go to the new site.
2. The second example using java script is handy if you have a number of domain names (for whatever reason) but want all names to point to the same domain.
Just add this to the top of your document:
<script language="JavaScript">
<!--
if( -1 == location.href.
toLowerCase().
indexOf('mydomainA.com') )
{
location.href = 'http://mydomainA.com';
}
// -->
</script>
The above code will check if 'mydomainA.com' is part of the code and if not will immediately redirect to 'http://mydomainA.com'
Option 2 is best I think unless you want to actually inform your visitor of the change then option 1 can be a good idea.
#4
Scooby Senior
iTrader: (1)
Join Date: Nov 2000
Location: Wildberg, Germany/Reading, UK
Posts: 9,706
Likes: 0
Received 73 Likes
on
54 Posts
If your using apache you can add this line to your httpd.conf file.
Redirect permanent /path from server root http://new url
ie
Redirect permanent /www/htdocs http://www.blah.com
do not use the full path from root as it won't work just go from your serverroot.
Redirect permanent /path from server root http://new url
ie
Redirect permanent /www/htdocs http://www.blah.com
do not use the full path from root as it won't work just go from your serverroot.
#5
Scooby Senior
iTrader: (1)
Join Date: Nov 2000
Location: Wildberg, Germany/Reading, UK
Posts: 9,706
Likes: 0
Received 73 Likes
on
54 Posts
stick this php script in your document root and call it index.php
<?php
/************************************************** ******************
* Dies ist ein PHP Script, das zur Weiterleitung von verschiedener *
* Domains auf verschiedene Ziele gebraucht wird. In dem Hash $parse *
* können beliebig viele Domainnamen angegeben werden und mit "=>" *
* getrennt, dahinter ihre Ziele. So wird "domain2.de" auf *
* ordner2/index.htm weitergeleitet. Die Default_Url diehnt dazu *
* Domains abzufangen die nicht im Hash vorkommen. *
* *
* Damit das Script arbeitet muss es im htdocs Verzeichnis liegen *
* Last Update 2003-07-29 10:23 *
************************************************** ******************/
$parse = parse_ini_file( "config.txt" );
$default_url = "index.html";
$http_host = $_SERVER[HTTP_HOST];
$http_host = preg_replace( "/www\./", "", $http_host );
if( $url = $parse[$http_host] ) {
$lines = file( "$url" );
foreach ($lines as $line_num => $line) {
//echo "$line_num: $line<br>";
if( preg_match( "/\<title\>(.*)\<\/title\>/", $line, $title )) {
break;
}
}
?>
<title><? echo $title[1]; ?></title>
<frameset>
<frame name='mainframe' src='<? echo $url; ?>'>
</frameset>
<?
}
else {
header("Location: $default_url");
}
?>
Then create a file called config.txt
to have 2 domain names pointing to the same website past this in it
yourdomain.com = a directory/index.html
yourdomain.co.uk = same directory/index.html
or you can use this to have seperate websites on seperate domain name on the same webspace just change the directory for the 2 domain names.
ie
yourdomain.com = cars/index.html
yourdomain.co.uk = bikes/index.html
then create the 2 directories in your document root
cars
bikes
or whatever you want them to be called in order to seperate your websites.
<?php
/************************************************** ******************
* Dies ist ein PHP Script, das zur Weiterleitung von verschiedener *
* Domains auf verschiedene Ziele gebraucht wird. In dem Hash $parse *
* können beliebig viele Domainnamen angegeben werden und mit "=>" *
* getrennt, dahinter ihre Ziele. So wird "domain2.de" auf *
* ordner2/index.htm weitergeleitet. Die Default_Url diehnt dazu *
* Domains abzufangen die nicht im Hash vorkommen. *
* *
* Damit das Script arbeitet muss es im htdocs Verzeichnis liegen *
* Last Update 2003-07-29 10:23 *
************************************************** ******************/
$parse = parse_ini_file( "config.txt" );
$default_url = "index.html";
$http_host = $_SERVER[HTTP_HOST];
$http_host = preg_replace( "/www\./", "", $http_host );
if( $url = $parse[$http_host] ) {
$lines = file( "$url" );
foreach ($lines as $line_num => $line) {
//echo "$line_num: $line<br>";
if( preg_match( "/\<title\>(.*)\<\/title\>/", $line, $title )) {
break;
}
}
?>
<title><? echo $title[1]; ?></title>
<frameset>
<frame name='mainframe' src='<? echo $url; ?>'>
</frameset>
<?
}
else {
header("Location: $default_url");
}
?>
Then create a file called config.txt
to have 2 domain names pointing to the same website past this in it
yourdomain.com = a directory/index.html
yourdomain.co.uk = same directory/index.html
or you can use this to have seperate websites on seperate domain name on the same webspace just change the directory for the 2 domain names.
ie
yourdomain.com = cars/index.html
yourdomain.co.uk = bikes/index.html
then create the 2 directories in your document root
cars
bikes
or whatever you want them to be called in order to seperate your websites.
Last edited by Wurzel; 08 March 2006 at 09:29 AM.
#6
Scooby Regular
Join Date: Dec 2003
Location: cheshire
Posts: 1,180
Likes: 0
Received 0 Likes
on
0 Posts
Or use this one just pop your taget url in
<html>
<head>
<title>Redirection </title>
<noscript>
<meta http-equiv="refresh" content="2; URL=redirectiontarget.htm">
</noscript>
<script language="JavaScript">
<!--
var sTargetURL = "http://www.YourURLHere.com";
function doRedirect()
{
setTimeout( "window.location.href = sTargetURL", 2*1000 );
}
//-->
</script>
<script language="JavaScript1.1">
<!--
function doRedirect()
{
window.location.replace( sTargetURL );
}
doRedirect();
//-->
</script>
</head>
<body onload="doRedirect()">
<p>Loading <a href="redirectiontarget.htm">www.Your URL.com</a></p>
<p>In approx. 2 seconds the redirection target page should load.<br>
If it doesn't please select the link above.</p>
</body>
</html>
<html>
<head>
<title>Redirection </title>
<noscript>
<meta http-equiv="refresh" content="2; URL=redirectiontarget.htm">
</noscript>
<script language="JavaScript">
<!--
var sTargetURL = "http://www.YourURLHere.com";
function doRedirect()
{
setTimeout( "window.location.href = sTargetURL", 2*1000 );
}
//-->
</script>
<script language="JavaScript1.1">
<!--
function doRedirect()
{
window.location.replace( sTargetURL );
}
doRedirect();
//-->
</script>
</head>
<body onload="doRedirect()">
<p>Loading <a href="redirectiontarget.htm">www.Your URL.com</a></p>
<p>In approx. 2 seconds the redirection target page should load.<br>
If it doesn't please select the link above.</p>
</body>
</html>
Thread
Thread Starter
Forum
Replies
Last Post
bluebullet29
General Technical
9
05 October 2015 02:17 PM