Support / KnowledgeBase

 
Search the KnowledgeBase Search

How do I use symlinks to redirect my site?

  • Applies to: Grid

  • Difficulty: Medium

  • Time needed: 20 minutes

  • Tools needed: SSH

 
  • Applies to: Grid
    • Difficulty: Medium
    • Time Needed: 20
    • Tools Required: SSH

Overview

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:

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.

Instructions

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.

TIP:

If you want the URL to change to the target domain, you should use a 301 Redirect instead.

  1. Connect to your server via SSH.
  2. Move into the domains directory.
    
    cd domains
    
  3. Delete any existing empty folders for your alternate domains. DO NOT delete the folder for the domain that has the content.

    CAUTION:

    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
    
  4. 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.

CAUTION:

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.

NOTE:

  • You will need SSH access to complete the steps outlined in this article. See here for more details.
  1. Connect to your Grid using SSH and go to your domains directory:
    
    cd /home/00000/domains/
    
  2. Create your sub-domain directory and navigate inside the directory:

    CAUTION:

    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
  3. 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
  4. Add the Options +FollowSymLinks directive to a newly created htaccess file using the echo command:
    echo 'Options +FollowSymLinks' > .htaccess

Resources

 

Continue