Multiple sites in subdirectories, main site in root

Using a single web hosting account to host multiple sites

Multiple sites in subdirectories, main site in root

Postby tommygeorge » Wed Mar 14, 2007 9:58 am

Please forgive me if this is already covered, I swear I've searched and read and looked and searched and read. I'm tired and desperate.

I'm hosting multiple domains on a shared account under one root.
My primary domain is obviously hosted in root, and other subsequent domains have their roots based in subdirectories 'therein'.

I installed wordpress in root for the primary domain (domain1.com/.htaccess) and the htaccess looks like so:

Code: Select all
#trying to force 'WWW' Prefix.
RewriteEngine On
RewriteCond %{HTTP_HOST} ^domain1\.com
RewriteRule ^(.*)$ http://www.domain1.com/$1 [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


I have domain2 in '/domain2.com/' where it's files are, and a copy of Wordpress installed at '/domain2.com/blog/'.

To attempt to force the 'WWW' prefix for domain2.com, here's domain2.com/.htaccess :

Code: Select all
RewriteBase /
RewriteEngine On
RewriteCond %{HTTP_HOST} ^domain2\.com
RewriteRule ^(.*)$ http://www.domain2.com/$1 [R=301,L]
ErrorDocument 404 /404.html


Which seems to work fine, even the custom error doc (that gets over-ridden once in the /blog/ dir anyway)... but any URL to "domain2.com/blog/..." doesn't get the WWW prefix added to it.

I *thought* that htaccess worked on all subdirectories, so I left the 'domain2.com/blog/.htaccess' as follows:

Code: Select all
# BEGIN WordPress
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
</IfModule>
# END WordPress


When I tried to correct it to force the WWW I somehow ended up at 'domain2.com/domain2'. Several other configurations that normally work give a 500 error.

How can I force the WWW on 'domain2.com/blog/whatever' and maintain the query string? The only way I've gotten it to work sent me back to "www.domain2.com" without the rest of the URL.

[there were other larger problems and lots of 500 errors, but I think they've smoothed out, so hopefully this will be my only question.]

Thanks so much!
tommygeorge
 
Posts: 3
Joined: Wed Mar 14, 2007 9:30 am

Postby richardk » Wed Mar 14, 2007 3:27 pm

Try
Code: Select all
# BEGIN WordPress
<IfModule mod_rewrite.c>
  RewriteEngine On

  RewriteCond %{HTTP_HOST} ^(domain2\.com)$ [NC]
  RewriteRule .* http://www.%1%{REQUEST_URI} [R=301,L]

  RewriteCond %{SCRIPT_FILENAME} !-f
  RewriteCond %{SCRIPT_FILENAME} !-d
  RewriteRule . /index.php [L]
</IfModule>
# END WordPress
richardk
 
Posts: 8800
Joined: Wed Dec 21, 2005 7:50 am

thanks...

Postby tommygeorge » Wed Mar 14, 2007 9:54 pm

Thanks for the reply, I notice how you're pretty much the "question answerer" around here and I really appreciate it.

New problem...
When I put your above listed code into '/domain2.com/blog/.htaccess' Only real files loaded... the rewrites that wordpress was using started generating 404's.

So moved it out and placed your code in '/domain2.com/.htaccess', where it still seems to work alright, but if you go to a functioning rewrite url (domain2.com/blog/post-name) it does *not* prefix the URL with 'WWW'.

When an .htaccess exists in a directory, does it automatically cancel out any rules set by directories above it?

Is there a way to rearrange the wordpress htaccess to use the 'WWW' redirect before attempting to rewrite for wordpress?

Or is this just an issue I'll have to deal with, being that I can't actually edit httpd.conf files and the like?

Thanks so much, again, for your help,

tommygeorge
tommygeorge
 
Posts: 3
Joined: Wed Mar 14, 2007 9:30 am

Postby richardk » Fri Mar 16, 2007 1:07 pm

Try this in /domain2.com/blog/.htaccess
Code: Select all
# BEGIN WordPress
<IfModule mod_rewrite.c>
  RewriteEngine On
  RewriteBase /

  RewriteCond %{HTTP_HOST} ^(domain2\.com)$ [NC]
  RewriteRule .* http://www.%1%{REQUEST_URI} [R=301,L]

  RewriteCond %{REQUEST_FILENAME} !-f
  RewriteCond %{REQUEST_FILENAME} !-d
  RewriteRule . /index.php [L]
</IfModule>
# END WordPress


Or this in /domain2.com/.htaccess
Code: Select all
ErrorDocument 404 /404.html
Options +FollowSymLinks

RewriteEngine On

RewriteCond %{HTTP_HOST} ^(domain2\.com)$ [NC]
RewriteRule .* http://www.%1%{REQUEST_URI} [R=301,L]

and this added to the original /domain2.com/blog/.htaccess
Code: Select all
RewriteOptions inherit
richardk
 
Posts: 8800
Joined: Wed Dec 21, 2005 7:50 am

Postby tommygeorge » Fri Mar 16, 2007 8:46 pm

/blog/ is forwarding to WWW, but always to the /blog/index.php page, and doesn't seem to pass the other args or something (when attempting to access something like '/blog/post-name/2007/' it simply forwards to index.php after adding the WWW).

Looks like I'm stuck with my little problem, which shouldn't be too bad, because all the links on the site are automatically generated with it... so I guess it shouldn't cause google or anyone to stumble too hard.

Thanks for the help.

Not sure that you're not already a genius in it already or anything, but if you ever get stuck with some PHP or Database development issues, let me know, I owe you a couple minutes of help, at least.

= )

Thanks again.
tommygeorge
 
Posts: 3
Joined: Wed Mar 14, 2007 9:30 am

Postby richardk » Sun Mar 18, 2007 2:40 pm

Try this in /domain2.com/.htaccess (without /domain2.com/blog/.htaccess)
Code: Select all
ErrorDocument 404 /404.html
Options +FollowSymLinks

RewriteEngine On

RewriteCond %{HTTP_HOST} ^(domain2\.com)$ [NC]
RewriteRule .* http://www.%1%{REQUEST_URI} [R=301,L]

RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^blog/.+$ /index.php [L]


Or you could add a little test to the beginning of index.php
Code: Select all
if(strpos(getenv('HTTP_HOST'), 'www.') !== 0)
{
  header('Location: http://www.' . getenv('HTTP_HOST') . getenv('REQUEST_URI'), true, 301);
  exit();
}
richardk
 
Posts: 8800
Joined: Wed Dec 21, 2005 7:50 am


Return to Domain Handling

Who is online

Users browsing this forum: No registered users and 36 guests

cron