Forum Moderators: phranque
I am having an issue trying to force the www in front of the URL in one of my domains. Here is as much info as I can provide:
I have 2 domains both hosted by HostGator, domain 1 is the primary one and is located in the root (/public_html/ as accordance to CPanel), and the other is located in the folder /public_html/domain2.net
Domain 2 was added via CPanel's "Addon Domain" function. I guess it also created a subdomain domain2.domain1.com by default, but I don't know if that is of any importance.
I installed WordPress on both domains via Fantastico. Each folder or domain I guess has its own .htaccess
I edited the .htaccess in the root for domain1.com with the following code:
RewriteEngine On
RewriteCond %{HTTP_HOST} !^www\.
RewriteRule ^ [%{HTTP_HOST}%{REQUEST_URI}...] [L,R=301]
and the redirect works perfect, makes the URL www by default.
However I tried to edit the .htaccess for domain2.net, which is located in /public_html/domain2.net, with the same code, but it creates an endless redirect.
I can see in the page loading status in the bottom left corner of Firefox that it keep alternating between [domain2.net...] and [domain2.net...] (Waiting for domain2.net, Waiting for www.domain2.net), and ultimately gives up, giving this error:
"Firefox has detected that the server is redirecting the request for this address in a way that will never complete."
So what did I do wrong with domain 2? I fooled with different variations of the redirect and nothing worked, it kept yielding the same error.
Oh and both domains were registered on Godaddy before changing the nameservers, if that is of any importance.
Thanks in advance for any suggestions.
Best Regards,
Adam
I am just not sure what is causing it to revert to the URL w/o www.
This is what my .htaccess for domain1.com currently looks like:
-----------------------------------------------
RewriteEngine On
RewriteCond %{HTTP_HOST} !^www\.domain1\.com [NC]
RewriteRule ^(.*)$ [domain1.com...] [R=301,L]
# BEGIN WordPress
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
</IfModule>
# END WordPress
------------------------------------------------
.htaccess for domain2.net is the same but w/o the first 3 lines.
Any ideas of where to look for what is causing domain2.net to remove the www from the url would be much appreciated. :)
If you're going to use mod_rewrite and other custom code in .htaccess, then try to avoid using the control panel for *anything* unless it's the only way to do it; control panels typically 'write' sloppy and inefficient config code (because they are trying to be 'generic') and have a penchant for overwriting manually-implemented customizations. So, it's a good idea to always keep current backups of your customization files...
Frankly, I prefer hosts that don't provide a control panel, and just sign up for a unique IP address, and do it all myself.
Jim
[edited by: jdMorgan at 12:20 am (utc) on Oct. 19, 2009]
You'll need something like this in the primary domain .htaccess to stop any of the rewrites affecting the add-on domain:
RewriteRule ^domain2\.net - [L] something is forcing it to REMOVE the www from the url
Don't forget that WordPress itself does redirection - make sure the correct version (www or non-www) is configured in the WordPress administration section. Otherwise you risk a loop as you .htaccess says one thing and WordPress another.
I prefer hosts that don't provide a control panel, but just sign up of a unique IP address, and do it all myself.
I don't mind control panels as such (although they do tend to write bad code for .htaccess and I always do that manually via SSH). I do however have a deep antipathy towards cPanel, and in particular the way it always sets up subdomains or "add-on" domains as subdirectories of the main domain, and thus creating "nested" document roots where the .htaccess of the primary domain interferes with the secondary ones.
This setup is seen these days as "normal" because cPanel is in such widespread use, but in reality it is a very poor way to set up a server, and is an ugly hack used to make things easier for the cPanel script.
[edited by: encyclo at 12:24 am (utc) on Oct. 19, 2009]
It would be simpler to just add "RewriteOptions none" in the lower-level .htaccess file, if indeed this is an inheritance problem. From the sound of it though, domain2 has its own DocumentRoot, and won't/can't share the domain1 .htaccess file.
Jim