Forum Moderators: phranque

Message Too Old, No Replies

Issue trying to force www with cpanel and multiple domains

         

adamcap

8:09 pm on Oct 18, 2009 (gmt 0)

10+ Year Member



Hey there,

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

adamcap

10:49 pm on Oct 18, 2009 (gmt 0)

10+ Year Member



Ok quick updates, removed the redirect from the .htaccess from domain2.net and realized that something is forcing it to REMOVE the www from the url. That is what caused the endless redirect.

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

jdMorgan

11:12 pm on Oct 18, 2009 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



I'd guess that either you 'created' the second domain as "domain2.com" instead of "www.domain2.com", or that the control panel 'conveniently' dropped the "www" from domain2 if you did indeed try to define it as "www.domain2.com."

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]

encyclo

12:20 am on Oct 19, 2009 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Welcome to WebmasterWorld adamcap :)

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]

jdMorgan

12:23 am on Oct 19, 2009 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



The HTTP_HOST would need to be checked in a RewriteCond, as the RewriteRule can't see anything but the URL-path.

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

phparion

12:31 am on Oct 19, 2009 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



it is your WORDPRESS CRAZY REDIRECTION :) you do not need www thingy in htaccess if used in wordpress. New version handles the non-www redirection to www itself. :)

adamcap

1:10 am on Oct 19, 2009 (gmt 0)

10+ Year Member



Yeah it was the Wordpres settings. I feel so dumb haha. I guess I must have changed the settings for domain 1 but not 2.

And yeah I don't like how domain 2 is a subdomain, I don't know much about this kind of stuff but that seemed weird to me.

Thanks for all the help!

g1smd

8:19 am on Oct 19, 2009 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



In some cases the CanononicalName setting can be a culprit too - but not this time by the look of it.