...Redirect URLs with .htaccess

Any issues with adjusting your .htaccess file fall under our Best Effort support policy. Best Effort does not include content management, coding or designing for your websites. We may also direct you to a better resource for your issue, such as Plugin Developer, Designer, Software Author etc. Best Effort is not covered under the same SLA's as our supported services and does not guarantee any future support for any issue. Please understand that Best Effort issues may take longer to resolve.

If you decide to change domain names or change the organization of your site, you can set up URL redirects to make sure your website visitors aren't confused. An easy way to do this is with .htaccess files.

.htaccess is a hidden file that is commonly located in your web site’s public_html folder. Your website’s .htaccess file may already contain important settings. If your .htaccess file has existing settings, add the new code to what is already there. Do not delete the existing .htaccess file unless it is empty or you are absolutely sure it is okay to delete.

If you're having trouble with .htaccess settings, don't hesitate to contact our Heroic Support team. Some customized settings might require your web developer, but we can help with many .htaccess questions.

To edit your .htaccess file, you will need to re-create the file yourself and upload it to the server using SFTP. Before making any changes to configuration files, we strongly recommend you make a backup of the file. Once you've decided what you want to add to your .htaccess file, follow these simple steps:

  1. Log into your server via SFTP.
  2. Locate and download your .htaccess file. It will usually be located in your content folder. If you don't have a .htaccess file, you can create a file called .htaccess on your computer to hold your configurations.
  3. Open the file via your favorite text editor
  4. Add these lines to your file:
    # enable basic rewriting
    RewriteEngine on
  5. Then copy and paste your new configurations into the .htaccess file and save the file.
  6. Upload this back to the directory you originally took your .htaccess file from.
  7. Test your work by going to your website and viewing the pages you wanted to redirect.

Redirecting Webpages and Whole Websites

To redirect individual pages on your website, you use 301 and 302 redirects. A 301 redirect is a permanent redirect, and a 302 redirect is a temporary redirect. These redirects tell the server to send traffic to the new location. They also tell website visitors and search engines where the content has moved.

Redirect 301 /old.html http://www.mysite.com/new.html

Replace /old.html with the directory path of your old page and http://www.mysite.com/new.html with the URL of your new page. This will send any visitors who want to access mysite.com/old.html to the page mysite.com/new.html.

You can also redirect a whole website this way.

Redirect 301 / http://www.mysite.com/

This is often used to change an existing domain to a new domain name.

URL Rewrites

Rewrites are similar to redirects because they also point one target URL to another URL, but this is actually converted by the web server while handling the traffic. Think of it as using a pencil and eraser to change a name as opposed to using a sign to point to the new name.

The most common URL rewrites force sites to have URLs either with or without "www."

Forcing Non-www Site Addresses

When you add this information to your .htaccess file, any visitors who type in www.mysite.com will be sent to mysite.com.

Options +FollowSymLinks 
RewriteEngine on
RewriteCond %{HTTP_HOST} .
RewriteCond %{HTTP_HOST} !^mysite\.com
RewriteRule (.*) http://mysite.com/$1 [R=301,L]

Replace mysite.com with your domain. If you have a different top-level domain (e.g., .net or .org instead of .com), use that top-level domain instead of ".com." Don't remove the "\" as it is needed for the correct syntax.

Forcing www Site Addresses

Options +FollowSymLinks 
RewriteEngine on
RewriteCond %{HTTP_HOST} ^mysite.com [NC]
RewriteRule ^(.*)$ http://www.mysite.com/$1 [L,R=301]

Replace mysite.com with your domain. If you have a different top-level domain (e.g., .net or .org instead of .com), use that top-level domain instead of ".com." Don't remove the "\" as it is needed for the correct syntax.

Have more questions? Submit a request
Powered by Zendesk