hosted by liquidweb


Go Back   Web Hosting Talk : Web Hosting Main Forums : Programming Discussion : type domain.com and it loads www.domain.com
Reply

Programming Discussion Discussions related to web programming languages and other related issues. Topics may include configuration, optimization, practical usage and database connectivity.
Forum Jump

type domain.com and it loads www.domain.com

Reply Post New Thread In Programming Discussion Subscription
 
Send news tip View All Posts Thread Tools Search this Thread Display Modes
  #1  
Old 09-04-2005, 07:27 PM
jdk jdk is offline
Aspiring Evangelist
 
Join Date: Jul 2004
Posts: 375

type domain.com and it loads www.domain.com


How would I make it so when a user types in my site using domain.com it will automatically open up www.domain.com. An example would be when you type in google.com it goes to www.google.com. I am assuming it is something I can put in an .htaccess file

Reply With Quote


Sponsored Links
  #2  
Old 09-04-2005, 07:44 PM
jdk jdk is offline
Aspiring Evangelist
 
Join Date: Jul 2004
Posts: 375
Found the solution for everyone.

Canonical Hostnames
Description:
The goal of this rule is to force the use of a particular hostname, in preference to other hostnames which may be used to reach the same site. For example, if you wish to force the use of www.example.com instead of example.com, you might use a variant of the following recipe.
Solution:
# For sites running on a port other than 80
RewriteCond %{HTTP_HOST} !^fully\.qualified\.domain\.name [NC]
RewriteCond %{HTTP_HOST} !^$
RewriteCond %{SERVER_PORT} !^80$
RewriteRule ^/(.*) http://fully.qualified.domain.name:%{SERVER_PORT}/$1 [L,R]

# And for a site running on port 80
RewriteCond %{HTTP_HOST} !^fully\.qualified\.domain\.name [NC]
RewriteCond %{HTTP_HOST} !^$
RewriteRule ^/(.*) http://fully.qualified.domain.name/$1 [L,R]

Reply With Quote
  #3  
Old 09-04-2005, 09:19 PM
Kijit Solutions Kijit Solutions is offline
Disabled
 
Join Date: Jul 2005
Posts: 135
IMO, this is alot more easier:

PHP Code:
    $url 'http://www.kijit.com'.$_SERVER['REQUEST_URI'];
    
$data explode('.'$_SERVER['HTTP_HOST']); 
    
$first $data[0];
    if (
$first != 'www')
    { 
// WWW
        
header('HTTP/1.0 301 Moved Permanently');
        
header('Location: '.$url);
        
header('Connection: close');
        exit;
    } 
Change "http://www.kijit.com" to whatever you want it directed to.

Reply With Quote
Sponsored Links
  #4  
Old 09-04-2005, 09:34 PM
jdk jdk is offline
Aspiring Evangelist
 
Join Date: Jul 2004
Posts: 375
Thanks I will give it a shot.

Reply With Quote
  #5  
Old 09-04-2005, 10:03 PM
jdk jdk is offline
Aspiring Evangelist
 
Join Date: Jul 2004
Posts: 375
Nope doesn't work.

Reply With Quote
  #6  
Old 09-07-2005, 10:37 PM
jdk jdk is offline
Aspiring Evangelist
 
Join Date: Jul 2004
Posts: 375
Anyone else with any suggestions?

Reply With Quote
Reply

Related posts from TheWhir.com
Title Type Date Posted
ICANN Publishes Details on Domain Seizure Process Web Hosting News 2012-03-09 15:38:48
Data Center Firm Switch Communications Sues Canadian Man Over Copyright Infringement Web Hosting News 2011-11-10 18:11:24
.XXX Domain Land Rush Period Begins Web Hosting News 2011-11-08 19:34:24
.XXX Domain Sunrise Period Opens Wednesday Web Hosting News 2011-09-06 20:50:41
Web Host FlexiHost Launches NZ Domain Lookup and Registration App Web Hosting News 2011-08-31 20:38:54


Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes
Postbit Selector

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off

Forum Jump
Login:
Log in with your username and password
Username:
Password:



Forgot Password?
Advertisement:
Web Hosting News:



 

X

Welcome to WebHostingTalk.com

Create your username to jump into the discussion!

WebHostingTalk.com is the largest, most influentual web hosting community on the Internet. Join us by filling in the form below.


(4 digit year)

Already a member?