Forum Moderators: phranque
The site structure is example.com/folder, where folder is a country name. There are 20 countries at present.
The problem is, sometimes (not always) when typing in www.example.com/folder it redirects to example.org/folder.
I also want to keep the www. at the front at all times.
I've tried many different .htaccess files and none seem to work the way I want. Is this indeed possible and if so, has anyone any ideas?
Thanks in advance.
I would recommend you find and correct the root cause of this problem. Using .htaccess to put a band-aid on the problem won't do anything but make it feel better for a little while, but it will leave in place a potentially-serious threat to the successful indexing and optimal ranking of the pages on the site.
I'd suggest running a link-checker such as Xenu on the site, and finding and fixing the links to the non-canonical URLs. Fix any URL-link that you find which results in any kind of error or redirect -- or which should, but does not.
Having done that, you can then use .htaccess to speed up the correction of any 'bad' URLs that have already been indexed in the search engines. This is becoming one of the phrases I type daily, but I guess it bears repeating: "The links on your pages define the 'real' URLs of your pages." No amount of .htaccess coding will change those URLs in any but a temporary and search-engine-robot-confusing way.
Jim
Again, a Webmaster is much better off avoiding its use, except when required -- for example, to modify httpd.conf or conf.d on shared virtual hosting. It must be understood for what it is - a facility for adding pre-coded or "canned" code snippets into server config and .htaccess files.
Within those limitations, it's OK, but can lead to some serious frustration and problems if used in an uninformed manner.
Basically, it violates Einstein's dictum: "Make everything as simple as possible, but no simpler."
Jim
You are right on most of your objections, but I'm a sort of hosting provider, and also keeps several websites and applications running, and while it would be indeed an extra overhead for me, that pays back on the customer satisfaction.
Enough has been said, just tell me which cliff it will be ;-)