Redirect http://domain.com to http://www.domain.com

Hi!

Does anyone that is being hosted on JodoHost have the following redirect working on their website(s)?

Redirect http://domain.com to http://www.domain.com

I tried the following code, but it does not work for some reason in my .htaccess file.

RewriteEngine on
rewritecond %{http_host}!^www\.domain\.com
RewriteRule ^(.*)$ http://www.domain.com/$1 [R=Permanent,L]

Thank you in advance.
 
umm you could *try* deleting the DNS (or alias) thingy that makes WWW. show the MyDomain.com bit

then add www as a subdomain and then go back to mydomain.com and go to Redirect (its in Web Service) ...

then you need to add in www.mydomain.com and tick the box "A permanent redirection for this resource" and then it should work

other than that i dont know, unless you use ASP to check if it has the www. and if it doesnt, redirect.

if the redirect doesnt work post back here and i'll give you sum ASP code to stick in the header of your home page

from wot i know i dont think the .htaccess file acctually works (on windows anyway)

mind if i ask why you want a redirect? as "www.mydomain.com" and "mydomain.com" show the same content anyway
 
.htaccess is unix only.

I figured trueblue was talking about a unix account to even attempt it.

:)
 
Hi Scotty 32!

I would greatly appreciate the ASP code to redirect because my main page is called index.asp and that seems the simpliest way to me.

Thank you in advance.
 
create an include, or if you have an include you put in EVERY page put this in there
if you connect to any databases close them off JUST above the redirect where my comment is

Code:
<%
  if left(Request.ServerVariables("[font=Verdana,Arial,Helvetica]URL[/font]"),4) <> "www." then
 	'close any database connections or objects here
 	Response.Redirect("www." & Request.ServerVariables("[font=Verdana,Arial,Helvetica]URL[/font]") & Request.ServerVariables("[font=Verdana,Arial,Helvetica]SCRIPT_PATH[/font]"))
 end if
 %>

this should redirect you to the www.mydomain.com if people go to mydomain.com

as i havent tested it so (am pritty sure it will but..) if it doesnt work let me know

make sure this code goes are the top, before ANY html is processed - like i said above, its best in an include so you can put it in all your files (incase someone is linked to the site from another site or something) it'll automatically take them to the page they tried to view on the non www. site

hope it helps
 
um hi sorry i havent replied my email account said that the "notification email" was spam ?(

am VERY sorry i never tested the script, i got the ServerVaribles thingys from a site i found off google (theres a code that shows all the ones that work on your server)

anywho - the correct code (after testing) is...

Code:
<%
   if left(Request.ServerVariables("SERVER_NAME"),4) <> "www." then
 	 'close any database connections or objects here
 	 Response.Redirect("http://www." & Request.ServerVariables("SERVER_NAME") & Request.ServerVariables("PATH_INFO"))
  end if
  %>

this WILL work, the reason for the problem you got was becose i never added the "http://" in :( which is kinda embarresing

anyway this new code WILL work
 
Back
Top