WWW and non-WWW URLs. Two different sites

I just noticed today that the website being created has a WWW or not WWW problem. If you go to http://www.taskconductor.com, this is another page with the same content as http://taskconductor.com.

If you were to log in (username: show@412customs.com , Pass: tester) at http://www.taskconductor.com, then try going to http://taskconductor.com (without WWW), it will force you again Sign in. 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 saw that this is a problem, but do I need to do a redirect? and if so, should it be index.php? I would rather have all my main content on index.php.

How can I get around this?

+6
source share
4 answers

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

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

This allowed cookies to be set only on any type of page. If he was at http://taskconductor.com, he would set a cookie for this, and also the same if he was http://www.taskconductor.com.

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

An additional "/" indicates that the cookie works in any of the directories under the root. The ".taskconductor.com" part will indicate which domain to use. The fact that it has a period before the name of the website indicates that this cookie will work on any subdomain or its own domain.

Thanks to everyone for the answers and help! Now everything works! THANKS!

+4
source

Do you know which web server you are using? If you are using apache, you can rewrite the url in the .htaccess file. This will allow you to combine all your traffic with your domain other than www. 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/

+3
source

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

+2
source

If you explicitly set the cookie domain to taskconductor.com (without www), then the same cookie set will be used for both www and the bare domain. You just need to change your PHP to specify a cookie domain.

I would recommend that you do what others offer and do redirect to whatever version you want to use as the canonical URL. Bad practice is to have duplicate content in multiple (child) domains. But, it is also a good idea to understand the scope of the cookie area that you set.

0
source

Source: https://habr.com/ru/post/891854/


All Articles