Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

WWW and non-WWW URL. Two different sites

Tags:

html

redirect

I just noticed today that a website I am creating has the WWW or non-WWW problem. If you go to http: //www.taskconductor.com, it is a different page with the same content as just http: //taskconductor.com.

If you were to login (username: [email protected], Pass: tester) at http: //www.taskconductor.com, then try to go to http: //taskconductor.com (without the WWW), it will make you log in again. Then as you can see, when you check your cookies, you can see that there are two sets of cookies. One for http: //taskconductor.com and one for http: //www.taskconductor.com.

I have seen that this is a problem, but do I need to make a redirect? and if so, does it have to be index.php? I would really prefer to have all of my main content on index.php.

How can I get around this?

like image 874
ntgCleaner Avatar asked Jul 02 '11 00:07

ntgCleaner


3 Answers

Do you know what web server you are using? If you're using apache, you can rewrite the URL in the .htaccess file. This will allow you to funnel all your traffic to with your non-www domain. I did a quick google and found this sample code:

RewriteEngine On
RewriteCond %{HTTP_HOST} ^www.example.com$ [NC]
RewriteRule ^(.*)$ http://example.com/$1 [R=301,L]

Source: http://yoast.com/how-to-remove-www-from-your-url-with-mod_rewrite/

like image 136
patorjk Avatar answered Sep 16 '22 16:09

patorjk


I was able to set my php "setcookies" to have a specified domain.

My original setcookie string was: setcookie('ver_ame', $email, time()+2592000);

This only allowed the cookie to be set on whatever type of page it was on. If it were on http: //taskconductor.com it would set the cookie for that, and also the same if it were http: //www.taskconductor.com.

If your setcookie string is: setcookie('ver_ame', $email, time()+2592000, "/", ".taskconductor.com");

The additional "/" shows the cookie to work on any of the directories under the root. The ".taskconductor.com" part would be showing which domain to use. The fact that it has a period before the web name shows that this cookie will work on any subdomain or its own domain.

Thank you all for the responses and help! It all works now! THANK YOU!

like image 35
ntgCleaner Avatar answered Sep 16 '22 16:09

ntgCleaner


Better than using URL rewrites is to set your cookies to work for subdomains. For example, if you set the cookie for mydomain.com, then it will not work for sub.mydomain.com. However, if you set the cookie for .mydomain.com (notice the period), then it will work for mydomain.com, sub.mydomain.com, foobar.mydomain.com etc.

like image 25
Richard Pianka Avatar answered Sep 17 '22 16:09

Richard Pianka