What is your favorite way do redirect all pages from the Non-WWW to WWW version? I know there are several different ways, I'd like to know how you do this in practice.
Code fragments and snippets welcomed.
|
2
|
|
|
|
|
6
|
As usual, there are a couple of different way to accomplish this task. First, let's discuss the use of Apache. Compared with passing the request to the backend language (in your case PHP), this is usually the preferred way. It's more lightweight and more fast because the webserver doesn't need to push additional levels to the execution stack. You can write the directive in your Apache configuration file or in the .htaccess file. If you have access to Apache config file, this is the best place. Otherwise, the .htaccess is fine too. The following directive redirects all request to any non-www host to the www-version of the site.
I usually prefer the code above rather the following one that instead selective.y redirect a single domain to the www-version. (note the difference on the second line)
Which one you should use depends on your specific case. If the former works, stick with it. Otherwise, if redirecting all host can cause some problem, use the latter. If you want to use PHP, you can use the following code.
|
||
|
|
|
1
|
Hi, I prefer to use server with this cofiguration active by default, or enable by the plesk. In any case I say to Google by web master central tool what's my favourite version and if server do not support redirect by default I write some code on the .htaccess file (only on Apache webserver):
|
|||||||||
|
|
1
|
The first version interfered with my host's system [fatcow.com] for access to the statistics files (Webalizer). Also it interfered (403) with the execution of my fommail script. The second version fixed both problems. Gerry cadrewebworks.com |
|||
|
|
0
|
if you have separate virtual hosts on your web server for non-www and www websites, you can simply put a line in .htaccess file on non-www vhost like this: Redirect 301 / http://www.domain.tld/ |
||
|
|
|
0
|
What about if am not using a hosting and just a domain with Blogger.com account ? pls help soon i use payingptcsites.info and want to land on Www.payingptcsites.info |
||
|
|