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:
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
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:
- 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.
- 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.
- 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.
- 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