Redirect To a Different URL Using .htaccess Configuration

0 Flares 0 Flares ×

This is the third part of the .htaccess tutorial series. In this tutorial I will discuss about the redirects using .htaccess file configuration. Redirect rules help us in redirecting a visitor from one document to another URL within or out side of your website. For example if you have stopped serving from your old directory and want to redirect the visitor to new page which notifies “This service has been discontinued”. So let us see how to redirect to a different url.


Redirect To Different URL


So let’s see how you can redirect to a different URL using .htacces file configuration. Below is the configuration settings that you need to do. Make sure that you do the changes to the root level .htaccess file.

Redirect /MyDir/

In the above configuration we are telling the apache server that if any visitor requests any document under the directory “MyDir”, then redirect them to the URL


If you note here the second part of the configuration is a complete URL to which we are redirecting and not a relative path on your web server. So always make sure that whenever you are doing this configuration, the target part should be a complete URL and not a relative path. Another thing is, as the target part is a complete URL you can specify any valid URL in it, it can be within your domain or outside your domain.

So now let’s generalize the redirect configuration for .htaccess:

Redirect source-relative-path destination-complete-URL


So the source-relative-path should be replaced with the exact relative path to the document and destination-complete-URL should be replaced with the complete absolute URL of the target.


Warning: Syntax in the .htaccess file configuration are case sensitive and can cause internal server error if a single syntax is even wrong. So always be careful while you are editing the .htaccess file and make sure you maintain the proper cases.


+Ayodhyanath Guru holds a B.Tech degree in Electrical Engineering and has worked with various prestigious clients in the IT industry and presently working as a Software Engineer. He is a part time blogger and presently authors the Jafaloo.Com blog. Being a tech enthusiast Guru likes to surf the web and blogs about interesting technical topics like How-To guides, freewares, Tutorials, Software, Gadgets, web applications etc. Apart from blogging he likes coding in Java/J2EE and PHP.

You may also like...

0 Flares Twitter 0 Facebook 0 Google+ 0 LinkedIn 0 0 Flares ×