cancel
Showing results for 
Search instead for 
Did you mean: 

2 domains - 2 sites - Wordpress - Subfolders?

oakbydesign
Grafter
Posts: 35
Registered: ‎01-06-2014

2 domains - 2 sites - Wordpress - Subfolders?

Hello again.
There must be a straight forward answer to this?
I have 2 domains hosted with you, lets call them example1.co.uk and example2.co.uk.
example1.co.uk has had the DNS records changed to point to  91.136.8.9 (hostopia) and everything works well.
the database is live, the .htaccess is fine, and the user sees example.co.uk when they visit the homepage.  Easy.
Now, I have example2.co.uk that currently points to old (/htdocs) webspace and does not have the DNS records changed yet.
I have also set up a subfolder for example2.co.uk in the main /public folder from within myPhpAdmin and installed a another copy of WP as example1.co.uk has its own in the root of /public
I have also set up a database and user using MySqlManager and everything works well.
If I go to ccgi.username.plus.com I am directed to example1.co.uk, brilliant!
If I go to ccgi.username.plus.com/subfolder I can see the new Wordpress site and everything works well.
If I set the DNS records on example2.co.uk to point to 91.136.8.9, how can the server differentiate between the domains and point the example2.co.uk to the sub folder?
To complicate matters slightly, I am thinking of a third domain and would really like to put all websites in subfolders and get the domains to point to each folder, each with a copy of WP installed?
Important. On the homepage, the user needs to see example2.co.uk and not example2.co.uk/subfolder/
Hope all this makes sense.
PS - I am reletively competent at moving files, altering .htacess etc..., thanks!
Richard
29 REPLIES 29
TORPC
Grafter
Posts: 5,163
Registered: ‎08-12-2013

Re: 2 domains - 2 sites - Wordpress - Subfolders?

Perhaps you want to amend the http://www.domain1 dot co dotuk/ as when I accidental clicked on it, it redirected through 2 or 3 redirecting sites before landing on a random blog page
Then on a purpose click it redirected through http://splitter.ndsplitter.com/beam.php?target=aHR0cDovL2NsaWNrcy5iZXN0cXVhbGl0eXNlYXJjaC5jb20vZmx5P... then through http://ww20.domain1.co.uk/ then looped through a few times before finally landing on http://www.mysupermarket.co.uk/shelf/Dental?banner=56430&utm_medium=email&utm_source=MediaBuy_UK&utm...
oakbydesign
Grafter
Posts: 35
Registered: ‎01-06-2014

Re: 2 domains - 2 sites - Wordpress - Subfolders?

domain1 and domain2 are purely examples, not the real site.
oakbydesign
Grafter
Posts: 35
Registered: ‎01-06-2014

Re: 2 domains - 2 sites - Wordpress - Subfolders?

Also found this.
If you stick a .htaccess file in your root folder (create as 'my.htaccess', save as txt, upload as ascii, delete 'my', set permissions 640):
Code:
RewriteEngine on
RewriteBase /
RewriteCond %{REQUEST_FILENAME} -d
RewriteRule ^(.+[^/])$ $1/ [R,L]
RewriteCond %{HTTP_HOST} ^(www\.)?mydomain\.co\.uk$ [NC]
RewriteCond %{REQUEST_URI} !^/~username/folder/
RewriteRule (.*) /folder/$1
changing mydomain, username and folder (twice) appropriately, then your domain will point straight at your blog.
Could I put this code into a single htaccess file twice?  Once for domain1 pointing to domain1/subfolder and another for domain2 pointing to domain2/subfolder?
Thanks
TORPC
Grafter
Posts: 5,163
Registered: ‎08-12-2013

Re: 2 domains - 2 sites - Wordpress - Subfolders?

I gathered that, however as domain1 links to a site that can clearly be enquired about in regestering etc, & with the redirect, some may think there is something wrong with their browser / PC / device etc
oakbydesign
Grafter
Posts: 35
Registered: ‎01-06-2014

Re: 2 domains - 2 sites - Wordpress - Subfolders?

Point taken, I have changed the domain wording to example.  Thanks. 
TORPC
Grafter
Posts: 5,163
Registered: ‎08-12-2013

Re: 2 domains - 2 sites - Wordpress - Subfolders?

Your welcome Smiley
spraxyt
Resting Legend
Posts: 10,063
Thanks: 674
Fixes: 75
Registered: ‎06-04-2007

Re: 2 domains - 2 sites - Wordpress - Subfolders?

Quote from: oakbydesign

RewriteEngine on
RewriteBase /
RewriteCond %{REQUEST_FILENAME} -d
RewriteRule ^(.+[^/])$ $1/ [R,L]
RewriteCond %{HTTP_HOST} ^(www\.)?mydomain\.co\.uk$ [NC]
RewriteCond %{REQUEST_URI} !^/~username/folder/
RewriteRule (.*) /folder/$1

Could I put this code into a single htaccess file twice?  Once for domain1 pointing to domain1/subfolder and another for domain2 pointing to domain2/subfolder?

(code block spaced out for clarity)
Yes, you can do this, but need to make small changes. The first rewrite rule needs to occur once only. It adds a trailing slash on the address line if a directory is requested but the URL does not have one. Note that a slash will not be added for domain only requests.
The presence of ~username in the conditions for the last rewrite rule applied on the old Plusnet ccgi hosting, but this needs to be removed for Hostopia. (This condition is to prevent the rule looping, endlessly adding /folder/ .)
The rule should be terminated by marking it as "last" if it matches.
Based on Gabe's post here, allowing for any subdomain prefix (including none), with appropriate substitutions I think the following rules should meet your needs

RewriteCond %{HTTP_HOST} ^([^.]+\.)?yourdomain1\.co\.uk$ [NC]
RewriteCond %{REQUEST_URI} !^/cgi-bin/
RewriteCond %{REQUEST_URI} !^/yoursite1/
RewriteRule (.*) /yoursite1/$1
RewriteCond %{HTTP_HOST} ^([^.]+\.)?yourdomain2\.co\.uk$ [NC]
RewriteCond %{REQUEST_URI} !^/cgi-bin/
RewriteCond %{REQUEST_URI} !^/yoursite2/
RewriteRule (.*) /yoursite2/$1

Excluding /cgi-bin might or might not be necessary, depending how /public is set up. An exclusion will also be needed for any other folders you want to use that are not under /yoursite.
On each WordPress configuration page you would need to set the desired domain URLs (without /yoursite) to avoid the folder names appearing in address lines.
David
David
oakbydesign
Grafter
Posts: 35
Registered: ‎01-06-2014

Re: 2 domains - 2 sites - Wordpress - Subfolders?

Thanks, great answer.
I will set up to the domain and alter the htaccess file.
I have attached a small screenshot of my /public folder.
Would  be right in assuming the htaccess files sits in the /public folder and the 2 copies of WP and themes etc, sit in the subfolders?
I take it there are no htaccess files in these subfolders?
Thanks
spraxyt
Resting Legend
Posts: 10,063
Thanks: 674
Fixes: 75
Registered: ‎06-04-2007

Re: 2 domains - 2 sites - Wordpress - Subfolders?

Yes, that .htaccess file content is intended to go in /public. You might find there is already one there, added by Hostopia during migration. That would be to support Perl and CGI scripts in /public (possibly in /public/CGI-BIN if you have this). One of the first things I did after migration was move such scripts to the proper /cgi-bin and remove their /.htaccess from my root directory ( / ).
If you are intending to move your existing /public located WordPress installation into its own subfolder (that would be my choice) you need to be aware that as well as moving /wp-admin, /wp-content and /wp-includes there are also around 25 standard files to be moved.
The second WordPress installation would start off in its own (separate) subfolder. Note that you can share MySQL databases by using a different installation prefix (wp_, wp2_, etc).
There will be numerous .htaccess files in the WordPress folders, but these are part of WordPress and should not be changed by the user.
David
David
oakbydesign
Grafter
Posts: 35
Registered: ‎01-06-2014

Re: 2 domains - 2 sites - Wordpress - Subfolders?

David
Thanks again.
Just to be clear, can the htaccess file in the /public folder contain all information?  ie.. redirects for both sites, theme security code etc...?
Or would it be better to have a htaccess file in the /public showing the rewrite rules you gave earlier and 2 other htaccess files in the subfolders for the redirects for each site?
Richard
spraxyt
Resting Legend
Posts: 10,063
Thanks: 674
Fixes: 75
Registered: ‎06-04-2007

Re: 2 domains - 2 sites - Wordpress - Subfolders?

Yes, the .htaccess in /public can include information relating to individual domains, though if doing this I'd try to share rules. If rule sets tailored for each domain are needed, putting each of these into their respective subfolders would be my preference.
The rules rewriting domain filepaths into their subfolders must necessarily be in /public.
David
David
oakbydesign
Grafter
Posts: 35
Registered: ‎01-06-2014

Re: 2 domains - 2 sites - Wordpress - Subfolders?

Excellent, thanks!
oakbydesign
Grafter
Posts: 35
Registered: ‎01-06-2014

Re: 2 domains - 2 sites - Wordpress - Subfolders?

It didn't work.  I get the error
Internal Server Error
The server encountered an internal error or misconfiguration and was unable to complete your request.
Please contact the server administrator, or webmaster and inform them of the time the error occurred, and anything you might have done that may have caused the error.
More information about this error may be available in the server error log.

i did the following
Moved all files associated with site1 (oakbydesign) from the public folder to a subfolder called 'obd''
Put the htaccess code as follows in the public folder.
RewriteCond %{HTTP_HOST} ^([^.]+\.)?oakbydesign\.co\.uk$ [NC]
RewriteCond %{REQUEST_URI} !^/cgi-bin/
RewriteCond %{REQUEST_URI} !^/obd
RewriteRule (.*) /obd/$1
Also tried removing the \'s in the first line to read oakbydesign.co.uk$ [NC]
Also tried adding a www. at the beginning
My original htaccess that I moved over from /public to /public/obd looks like this.
# BEGIN WordPress
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteRule ^index\.php$ -
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php
</IfModule>
# END WordPress
Do I need to change any other files in WP, update links or anything in the database?
As the site works ok in the public folder, I have moved everything back for now.
I really wanted to launch a different and new WP site that is sat ready in another subfolder by tomorrow and was testing the oakbydesign site first by moving it also to a subfolder.
This new site currently points to PN webspace as it is a html website.
Thanks
Richard

Many thanks
Richard
oakbydesign
Grafter
Posts: 35
Registered: ‎01-06-2014

Re: 2 domains - 2 sites - Wordpress - Subfolders?

Done it! 
I had to change the upload folder (images) to read obd/wp-content/
AND
change the permissions on the htaccess foe to 640 not 644, i think.  Anyway 640 works!
The htaccess file in the public folder now looks like this
RewriteEngine on
RewriteBase /
RewriteCond %{REQUEST_FILENAME} -d
RewriteRule ^(.+[^/])$ $1/ [R,L]
RewriteCond %{HTTP_HOST} ^(www\.)?oakbydesign\.co\.uk$ [NC]
RewriteCond %{REQUEST_URI} !^/obd/
RewriteRule (.*) /obd/$1
Just need to point the next domain to hostopia and modify the htaccess.
Cheers