How can I force my site to always load "www" at the beginning when someone tries to go to it?
So we're clear, I mean when someone tries to go to "http://mysite.com" it'll automatically load/redirect to "http://www.mysite.com"
I use cPanel for hosting if it's host specific, I just can't seem to easily find any info on this online.
How to make my site always load as "www"
Page 1 of 17 Replies - 952 Views - Last Post: 21 July 2010 - 02:22 AM
Replies To: How to make my site always load as "www"
#2
Re: How to make my site always load as "www"
Posted 20 July 2010 - 03:46 PM
I'll ask my first question then see what you say: Why does it matter if they arrive at http://www.mysite.com or http://mysite.com?
#3
Re: How to make my site always load as "www"
Posted 20 July 2010 - 04:15 PM
PsychoCoder, on 20 July 2010 - 01:46 PM, said:
I'll ask my first question then see what you say: Why does it matter if they arrive at http://www.mysite.com or http://mysite.com?
Because I'm having login errors if they arrive http://mysite.com they login and for some reason I cannot figure out when they login at http://mysite.com and it redirects them to what should be the member login index page at http://www.mysite.com they're still logged out until they login again. However, if they start on http://www.mysite.com and they login then there's no issues.
I've tried to figure out how to fix the problem but I don't see anything wrong with my code, the only thing I can think is that it's reading it sort of as two different sites so the session variables aren't transferring over. (kinda like how Google Analytics requires you specify)
Also, if I did want to put analytics on it it would be easier to just have the www instead of having to look at how both performed.
#4
Re: How to make my site always load as "www"
Posted 20 July 2010 - 04:36 PM
I'm going to take a guess on your login problems. I'm betting it's the following.
- Your login system relies on cookies.
- Your cookies are set on the www subdomain specifically
- So requests from mysite.com don't get a hold of the cookies because the browser won't retrieve for a specific subdomain
I don't recommend differentiating between www subdomain and lack of subdomain. Accept both, prefer the mysite.com form (and redirect appropriately).
It's not a good idea to differentiate between www.mysite.com and mysite.com if there's no difference except the name. It makes analysis (as well as other things) harder.
- Your login system relies on cookies.
- Your cookies are set on the www subdomain specifically
- So requests from mysite.com don't get a hold of the cookies because the browser won't retrieve for a specific subdomain
I don't recommend differentiating between www subdomain and lack of subdomain. Accept both, prefer the mysite.com form (and redirect appropriately).
It's not a good idea to differentiate between www.mysite.com and mysite.com if there's no difference except the name. It makes analysis (as well as other things) harder.
#5
Re: How to make my site always load as "www"
Posted 20 July 2010 - 04:46 PM
Oler1s, on 20 July 2010 - 02:36 PM, said:
I'm going to take a guess on your login problems. I'm betting it's the following.
- Your login system relies on cookies.
- Your cookies are set on the www subdomain specifically
- So requests from mysite.com don't get a hold of the cookies because the browser won't retrieve for a specific subdomain
I don't recommend differentiating between www subdomain and lack of subdomain. Accept both, prefer the mysite.com form (and redirect appropriately).
It's not a good idea to differentiate between www.mysite.com and mysite.com if there's no difference except the name. It makes analysis (as well as other things) harder.
- Your login system relies on cookies.
- Your cookies are set on the www subdomain specifically
- So requests from mysite.com don't get a hold of the cookies because the browser won't retrieve for a specific subdomain
I don't recommend differentiating between www subdomain and lack of subdomain. Accept both, prefer the mysite.com form (and redirect appropriately).
It's not a good idea to differentiate between www.mysite.com and mysite.com if there's no difference except the name. It makes analysis (as well as other things) harder.
I appreciate the information as well as the suggestions. For the moment I just specifically redirected each page, which isn't going to be practical as the site grows since using cPanel's 301 redirect I have to manually put in each page.
I'll look into fixing the cookies, although at the moment I don't know how since I'm still a complete amateur when it comes to PHP.
#6
Re: How to make my site always load as "www"
Posted 20 July 2010 - 05:30 PM
PsychoCoder, on 20 July 2010 - 09:46 PM, said:
I'll ask my first question then see what you say: Why does it matter if they arrive at http://www.mysite.com or http://mysite.com?
It matters in a big way
- first it presents a cleaner cooperate image
- second, as already points out it can help with cookie sub domain errors
- and last, and most importantly it stops canonical URL issues
At OP: I was having a similar issues, and the method for setting domain wide sessions is discussed in depth in my thread here
Of course if you want to redirect not www. users to www. anyway you could add the following code to your htaccess file..
RewriteEngine on
Options +FollowSymLinks
RewriteCond %{HTTP_HOST} ^example.co.uk [NC]
RewriteRule ^(.*)$ http://www.example.co.uk/$1 [L,R=301]
#7
Re: How to make my site always load as "www"
Posted 20 July 2010 - 06:50 PM
PsychoCoder, on 20 July 2010 - 04:46 PM, said:
Why does it matter if they arrive at http://www.mysite.com or http://mysite.com?
It's fine configuring Apache vhosts if you only have a couple of domains, but anymore than 20 & it's a pain in the ass to manage now 40 vhosts configs. *that's one for each*
#8
Re: How to make my site always load as "www"
Posted 21 July 2010 - 02:22 AM
You can get the URL to redirect to your www. domain by editing your websites .htaccess file which is located at the root of your website.
Browse to your website directory using cPanel's file manager and edit the .htaccess file as follows:
Just change "yoursite.com" to your domain.
Browse to your website directory using cPanel's file manager and edit the .htaccess file as follows:
Options +FollowSymLinks
RewriteEngine on
RewriteCond %{HTTP_HOST} ^yoursite.com [NC]
RewriteRule ^(.*)$ http://www.yoursite.com/$1 [L,R=301]
Just change "yoursite.com" to your domain.
Page 1 of 1
|
|

New Topic/Question
Reply



MultiQuote





|