How to shorten a web address using .htaccess

Redirecting web addresses is a common use for .htaccess when addresses become too long or complicated. For example, if you had a blog running on your website and you wanted to share a post you had made the address could look something like:

Using .htaccess we could create a redirect that is easier to type and remember e.g.

This technique is often referred to as url rewriting. Here is what our .htaccess file would look like:

<IfModule mod_rewrite.c>
  RewriteEngine On
  RewriteRule ^/htaccess$ /how-to-use-htaccess-to-redirect-long-urls [L]

Lines 1 and 4 - Wrap our rewrite rule in a container that checks rewriting is available.

Lines 2 - Turns rewriting on.

Lines 3 - The rule says if there is a request for '' rewrite (redirect) it to ''. Finally the [L] means don't process any more rules.

Once you have created your .htaccess file you just need to upload it to the web folder for your hosting using FTP.

Related guides

  • How to shorten a web address using .htaccess
  • 301 and 302 Redirects: What to Use and When
  • What is a .htaccess file?
  • A Beginners Guide to Custom 404 Pages
  • Check out some of our related guides

    Need a hand? Search over a hundred step-by-step support guides