1 / 3
Caption Text
2 / 3
Caption Two
3 / 3
Caption Three margin testing

Wednesday, January 13, 2010

How can I force my site to add "www." before the URL if visitors don't enter it?

Zen Cart(tm) Tutorials and FAQs - How can I force my site to add "www." before...

Scenario:
Customer types in "example.com" when trying to enter your website.
In most cases this will let them get to your site fine.

BUT ... if you've configured your site to use "www.example.com" in all the URLs it generates, then the customer's next click will attempt to change the URL and (on some servers) may log them out if they were attempting login, etc. This is because of the way PHP session security works with setting a session cookie tied to a domain name, etc. The technical details can be read online elsewhere.

Also, in Internet Explorer, if you are using some fancy flyout CSS effects the addon script that drives this may not be "found" because of the change in domain name ... meaning that the menu won't work until the customer first does another click on your site.

There are a couple things to keep in mind to handle this:
  1. Always be consistent in your use of your domain name. If you're going to use "www.example.com", be sure to use it exactly that way everywhere. Don't drop the "www." unless you do it consistently in all places.
  2. In your SSL certificate, when you register one, you must specify a domain name. Again, be consistent. If you're using "www." in your URL, use it in your SSL certificate too.
  3. Ensure that your hosting company has configured a "www." address as an alias to your domain name ... so that "both" will work -- otherwise visitors might get a "domain not found" error instead of your site.
  4. If you are running on an Apache webserver, you can set up a .htaccess rule to automatically add the "www." into the URL if the customer forgets to include it. The following is what you'd put in your .htaccess to accomplish this:

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

--------------------
How to Remove the WWW Prefix from Your Domain Names Using Apache's mod_rewrite

To redirect any URL starting with (say) www.example.com to example.com, add the following code to your .htaccess file.

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

The above rules checks if the hostname in a URL contains www.example.com. If it does, the visitor is sent to example.com instead.

To use the rule, change all instances of "example.com" to your actual domain name. For the line beginning with RewriteCond, add a backslash ("\") before each of the full stops (or "periods") in your domain name.


No comments:

Post a Comment

Featured Post

Windows和Ubuntu双系统完全独立的安装方法

http://www.ubuntuhome.com/windows-and-ubuntu-install.html  | Ubuntu Home Posted by Snow on 2012/06/25 安装Windows和Ubuntu双系统时,很多人喜欢先安装windows,然...