cloudy cloudy

Author Topic: Domain redirection for WDL  (Read 4242 times)

0 Members and 1 Guest are viewing this topic.

Offline Softvark

  • Posts: 4,281
  • UK
    • The weather in Colchester
Domain redirection for WDL
« on: September 18, 2004, 10:36:07 AM »
Several people have registered WDL for a domain but they have more than one prefix. For example you might be able to get to the site by going to http://www.mysite.com or via http://mysite.com. The serial number is only valid for one of these sites so users can potentially get a serial number error. You can get around this by using this small javascript which will automatically redirect visitors to your site with the domain with the serial number.

To use enter this script into the html page between the <head></head> tags -

<script language="JavaScript"><!--
var loc = window.location.href;

var wrongdomain = 'http://www.mysite.com/weather/index.html';
var correctdomain = 'http://mysite.com/weather/index.html';

if (loc.toLowerCase().indexOf(wrongdomain) !=-1)
    location.href=correctdomain;

//-->
</script>

Make sure you enter your web paths into the variables above. Now anyone coming to your page via http://www.mysite.com/weather/index.html will automatically be redirected to http://mysite.com/weather/index.html and avoid the serial number error.

Julian

Offline TNETWeather

  • Kevin Reed (KrelvinAZ)
  • Posts: 5,939
  • Gremlins are at work...
  • Mesa, AZ
    • TNET Weather Station - Mesa AZ
Domain redirection for WDL
« Reply #1 on: October 06, 2004, 05:47:49 AM »
You can do this with the web server if you are using Apache with mod_rewrite enabled.

In the .htaccess file in the top directory of the website...

Code: [Select]
RewriteCond %{HTTP_HOST}   !^www\.mysite\.com [NC]
RewriteCond %{HTTP_HOST}   !^$
RewriteRule ^/(.*)         http://www.mysite.com/$1 [L,R]
This will take in input of just plain  http://mysite.com and turn it into http://www.mysite.com before handing it off to the web page.

You might need to add at the top

Code: [Select]
RewriteEngine onThis would work even if the user had javascript turned off.
« Last Edit: April 25, 2005, 02:08:57 PM by krelvinaz »

All you need is Time, Aptitude and Desire ... and you can build just about anything...

Offline Softvark

  • Posts: 4,281
  • UK
    • The weather in Colchester
Domain redirection for WDL
« Reply #2 on: October 06, 2004, 10:36:57 AM »
Yes there are lots of ways of doing this. For example if you have asp capability (running a Windows IIS box) then you can put this at the top of your asp page -

<%

Dim strWrongDomain, strCorrectDomain

strWrongDomain = "www.mysite.com"
strCorrectDomain = "mysite.com"

If Request.ServerVariables("http_host") = strWrongDomain Then
Response.Redirect "http://" & strCorrectDomain & Request.ServerVariables("URL")
End If

%>

Julian

Offline Eki

  • Posts: 299
  • Lohja, Finland
    • Virkkala Weather
Domain redirection for WDL
« Reply #3 on: October 06, 2004, 02:43:49 PM »
Hi Julian,

Now I can forget one problem in my site.

Many thanks!  :D

Cheers
Eki

Offline CaptDilli

  • Posts: 986
  • Little Switzerland NC USA
    • Little Switzerland Weather - NC - Butterfly Crossing
Domain redirection for WDL
« Reply #4 on: October 08, 2004, 01:42:39 AM »
Quote from: Eki
Hi Julian,

Now I can forget one problem in my site.

Many thanks!  :D

Cheers
Eki
Me too.
Sometimes a browser will insert a www. in front of the web address if the web address does not begin with a www.
These fixes are good.  Thank you. :D
BC
System Info:
XP Home, SP 3, Firefox 3.5.7, IE-7, Pentium 4 2.26GH, 1024MB RAM, Desktop, ADSL, No screen saver, http://littleswitzerlandweather.info/bfcrealtime.htm
http://littleswitzerlandweather.info/live/index.html