Hosting Two Sites on One Account

It will occasionally be beneficial to host two sites on the same account. This can be easily achieved by the correct directory structure and an .htaccess file.

Directory Structure

For this example we will be setting up site1 and site2. Connect to your web hosting account and navigate to the htdocs directory. Within the htdocs directory, create the two directories site1 and site2.

For example, from the command line:

ssh name.#@webssh.osu.edu
The user: [name.#] has access to the following sites:
--------------------------------------------------------------------
1: testsite1
2: testsite2
--------------------------------------------------------------------
Please choose [1 - 2]: 1
[testsite1@whadmprd01 ~]$ cdweb
[testsite1@whadmprd01 testsite1]$ cd htdocs
[testsite1@whadmprd01 htdocs]$ mkdir site1
[testsite1@whadmprd01 htdocs]$ mkdir site2

HTACCESS File

Then we need to create the .htaccess file in the htdocs directory.

Continuing the command line example right from where we left off:

[testsite1@whadmprd01 htdocs]$ vi .htaccess

The vi command will open a command line text editor so that you can edit the file. If you are not familiar with this kind of text editor, there will not be a significant visual change to your screen, but it will be open. Copy the template below, then press i in the text editor (i stands for insert so you can write to the file) and paste the template into the .htaccess file. Be sure to adjust the example site1 and site2 names to match your actual sites and directories.

RewriteEngine on
# For site1
RewriteCond %{HTTP_HOST} ^(www\.)?site1\.osu\.edu$ [NC]
RewriteCond %{REQUEST_URI} !^/site1/
RewriteRule ^(.*)$ /site1/$1 [L]

# For site2
#RewriteCond %{HTTP_HOST} ^(www\.)?site2\.osu\.edu$ [NC]
#RewriteCond %{REQUEST_URI} !^/site2/
#RewriteRule ^(.*)$ /site2/$1 [L]

Once the urls and directory names have been adjusted, press escape to exit the insert mode, then type :wq! to write and quit the file. To check your work, you can do:

[testsite1@whadmprd01 htdocs]$ cat .htaccess

This will output the file (without opening the text editor). Once complete, simply type exit to sever the ssh connection

[testsite1@whadmprd01 htdocs]$ exit
Connection to webssh.osu.edu closed.

Need More Information?

Is OSU Web Hosting right for you? Check your eligibility.

More questions? Check the support section or contact us.

Ready to get started? Request hosting now!