Notices
Computer & Technology Related Post here for help and discussion of computing and related technology. Internet, TVs, phones, consoles, computers, tablets and any other gadgets.

Web forwarding

Thread Tools
 
Search this Thread
 
Old 02 June 2004, 03:44 PM
  #1  
IanWatson
Scooby Regular
Thread Starter
 
IanWatson's Avatar
 
Join Date: Jul 2001
Location: maturin23 - 205GTi Drivers.com
Posts: 504
Likes: 0
Received 0 Likes on 0 Posts
Default 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
Old 02 June 2004, 03:49 PM
  #2  
molko
Scooby Regular
 
molko's Avatar
 
Join Date: Jun 2004
Location: UK
Posts: 638
Likes: 0
Received 0 Likes on 0 Posts
Default

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.
Old 02 June 2004, 04:13 PM
  #3  
IanWatson
Scooby Regular
Thread Starter
 
IanWatson's Avatar
 
Join Date: Jul 2001
Location: maturin23 - 205GTi Drivers.com
Posts: 504
Likes: 0
Received 0 Likes on 0 Posts
Default

Thanks matey - will give it a go!
Old 02 June 2004, 04:18 PM
  #4  
Wurzel
Scooby Senior
iTrader: (1)
 
Wurzel's Avatar
 
Join Date: Nov 2000
Location: Wildberg, Germany/Reading, UK
Posts: 9,706
Likes: 0
Received 73 Likes on 54 Posts
Default

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.
Old 02 June 2004, 04:26 PM
  #5  
Wurzel
Scooby Senior
iTrader: (1)
 
Wurzel's Avatar
 
Join Date: Nov 2000
Location: Wildberg, Germany/Reading, UK
Posts: 9,706
Likes: 0
Received 73 Likes on 54 Posts
Default

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.

Last edited by Wurzel; 08 March 2006 at 09:29 AM.
Old 02 June 2004, 05:48 PM
  #6  
sti555
Scooby Regular
 
sti555's Avatar
 
Join Date: Dec 2003
Location: cheshire
Posts: 1,180
Likes: 0
Received 0 Likes on 0 Posts
Default

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>
Related Topics
Thread
Thread Starter
Forum
Replies
Last Post
Rbon91
ScoobyNet General
49
21 November 2018 03:23 PM
Frizzle-Dee
Essex Subaru Owners Club
13
01 December 2015 09:37 AM
bluebullet29
General Technical
9
05 October 2015 02:17 PM
south_scoob
ScoobyNet General
22
03 October 2015 01:05 PM
JackClark
Computer & Technology Related
18
30 September 2015 02:00 PM



Quick Reply: Web forwarding



All times are GMT +1. The time now is 09:49 AM.