Redirect URLs using .htaccess

Sometimes you need to redirect some URL and/or page on your site to another one.
The feature is very useful if you have recently redesigned your site but you wish to keep

the old addresses working for various reasons (you have links to these pages from other

sites, some users may have the old pages bookmarked, etc).

The Apache web server provides several way for setting up redirects.

The most simple one is using the Redirect directive:

Redirect /folder http://www.example.com/newfolder

With such a line in your .htaccess if a visitor tries to load

http://www.example.com/folder, he will be redirected to http://www.example.com/newfolder.

Recently it has been talked a lot about Permanent redirects. The good news is that you can

add a status code to the Redirect directive. For example for Permanent 301 redirect you can

use:

Redirect permanent /folder http://www.example.com/newfolder

Another useful directive is the RedirectMatch. With it you can use regular expressions in

the redirect condition. For example

RedirectMatch ".html$" http://www.example.com/index.php

This will redirect all requests to files that end with .html to the index.php file.

There is another more powerful way to create redirects or even create transperant redirects

which requires ModRewrite. Please refer to the articles on mod_rewrite.
  • 44 Users Found This Useful
Was this answer helpful?

Related Articles

Can you provide a custom package for me?

Yes, most definitely. Simply open up a helpdesk ticket in the Sales department or contact us...

Force SSL/https using .htaccess and mod_rewrite

Sometimes you may need to make sure that the user is browsing your site over a secure...

Change PHP variables using .htaccess

If you need to change the way your PHP is working you can do that using .htaccess.Please, note...

Block Bad robots, spiders, crawlers and harvesters

There are lots of examples across the internet that use ModRewrite. We will provide such an...

Force www vs non-www to avoid duplicate content on Google

Recently, it has been talked a lot about Google and duplicate content as well as Google Canonical...