PHP and MySQL For Dummies
Book image
Explore Book Buy On Amazon

Sometimes you might want to get a little creative with your web hosting and set up a specific URL to redirect somewhere. It doesn’t take long to do and can make the URL shorter, more memorable, or easier to spell.

The following steps explain how to get more creative with redirects using cPanel:

  1. Log into cPanel using the details your host gave you when you first signed up.

  2. Scroll to the Domains section and click Redirects.

  3. Choose the type of redirect you want.

    Redirect choices are 301 and 302. These are standard numbers that the server uses to inform your browser of the redirect and give it more information so it knows what to do. A 301 redirect is a permanent redirect. This means that, as far as you know, this redirect will never change. Your browser then knows that it should update any bookmarks you have to the original URL.

    A 302 redirect is only a temporary redirect, which means you’re purposefully redirecting for a short time and this may be due to some maintenance or for a short-term project. The browser knows not to update its bookmarks because it needs to check every time you use the URL whether the redirect is still in place.

  4. Choose the domain name you want to redirect from the drop-down box.

    The drop-down box includes your primary domain and any add-on or parked domains under the account.

  5. Type the rest of the path to the file or folder you want to redirect.

    image0.jpg
  6. In the Redirects To box, type the full URL of the site, file, or page that you want to redirect to.

    You also need to include the protocol for the URL, which will normally be http://.

  7. Select what type of www. redirection you require.

    Normally this will be redirect with or without www. www. is normally simply the default hostname in your URL and your browser treats no hostname and www. as the same thing. It is possible to configure this differently, though, so that www. is a different page on your site. If that is the case on your site, you may need to choose one of the other www. redirection options.

  8. Select the Wildcard Redirect option, if desired.

    Wildcard redirects can be useful in certain circumstances, but are not always necessary. A wildcard redirect redirects to the same filename in the destination directory. This is useful if you change your domain name, but otherwise have your directory structure the same. For example, you might have a contact form for which your old URL was yourdomain.com/contact.htm and the correct new URL might be yournewdomain.com/contact.htm.

    The file structure is the same; only the domain name differs. In this case, if you do not use a wildcard redirect when somebody clicks a link or types into the browser yourdomain.com/contact.htm, instead of being redirected to the contact form on your new domain, that person would be redirected to the main page on your new domain (yournewdomain.com).

    If you do select wildcard redirect, though, the visitor will be redirected straight to the new contact form. This will not work if the filenames have changed.

  9. Click Add.

    Your redirect appears at the bottom of the screen.

You cannot edit redirects; instead, you have to delete and re-create them.

Redirects are done using commands placed in the .htaccess file in the document root of the main domain. When you create the redirects, they are automatically entered for you by the system at the end of that file. If redirects are not working, check the .htaccess file because other software may have placed commands before them that are overriding the new redirects.

For example, when you install WordPress, it creates a redirect that ensures that visitors can find the main page of the site. If this is the case, you should move your new redirects to be at the beginning of the .htaccess file because commands in that file are acted on in the order in which they are read.

You can create redirects for any path or filename within any domain you have added on or parked, and you can add and delete them any time you want. This means that you can easily redirect users for a short time when necessary and can also make shorter URLs to share with potential visitors that redirect to less memorable URLs on your website.

About This Article

This article can be found in the category: