This article will show you how to make the content displaying for example.com appear when visiting alt-example.com. A symlink, short for symbolic link, is one of the best ways to do this.
Before you start
Be sure to have the following:
- Add all your domains (alt-example.com in this example) as alternate domains in the AccountCenter. See Manage Domains: Adding a domain or subdomain for step by step directions.
- Enable SSH access for your Server Administrator and be able to connect to your Grid via SSH. For more information, please see: Connecting via SSH to your server.
READ ME FIRST
This article is provided as a courtesy. Installing, configuring, and troubleshooting third-party applications is outside the scope of support provided by (mt) Media Temple. Please take a moment to review the Statement of Support.
Symlink as a mirror
These instructions will create a file system link from one folder to another, allowing you to point multiple domains to the same alternate (or primary) domain folder. Essentially, this creates a mirror of your content from example.com to alt-example.com. The browser will display alt-example.com in the address bar.
If you want the URL to change to the target domain, you should use a 301 Redirect instead.
- Connect to your server via SSH.
Move into the domains directory.
Delete any existing empty folders for your alternate domains. DO NOT delete the folder for the domain that has the content.
Use the following command only for empty folders. This command will delete the specified folder, along with all of its contents. If you're more comfortable with FTP, you can also perform this step using your favorite FTP client.
rm -rf alt-example.com
Create the symlink for alt-example.com with the target of example.com. Be sure to replace the domain names in the example with your own domain names.
ln -s example.com alt-example.com
Here's the command breakdown:
- ln - Makes a link.
- -s - Designates a symlink.
- example.com - Your target folder. This is the one that has the content.
- alt-example.com - Your alias. This is the new alternate domain that currently has no content.
You should now be able to visit http://alt-example.com and see your website content that is also displayed on example.com.
DO NOT remove the symlink via FTP. FTP will actually follow the link to your real folder and delete all of your data. Instead use SSH to remove your symlink with this command:
rm -f alt-example.com
Point your sub-domain to a sub-directory on this domain
The example below will create a new sub-domain on a Grid named sub.example.com that will display content from the already existing sub-directory named sub located at example.com/sub.
These steps will NOT mirror or copy the content. All traffic to the new sub-domain will in fact be generated on the previous domain. Keep in mind that any changes made to example.com/sub will be immediately available at your new sub-domain.
- You will need SSH access to complete the steps outlined in this article. See here for more details.
Connect to your Grid using SSH and go to your domains directory:
Create your sub-domain directory and navigate inside the directory:
If your sub-domain already exists, it will have to be deleted first using the rm command. Make sure you have backed up any files first before recursively deleting any directories on your service.
mkdir sub.example.com && cd sub.example.com
Now, create a symbolic link that will use your already existing sub-directory on your other domain:
ln -s /home/00000/domains/example.com/html/sub html
Add the Options +FollowSymLinks directive to a newly created htaccess file using the echo command:
echo 'Options +FollowSymLinks' > .htaccess