HomeInternetHTTPRedirect webpages or URLs using .htaccess

Redirect webpages or URLs using .htaccess

The .htaccess file is a powerful tool that most casual users have not yet discovered. Here I’ll show how to use it to redirect users from one site to another. For this example, we will redirect users from /techrx/test to http://tech-recipes.com


This recipe requires you to be able to create, edit, and set permissions of files. In unix-like systems, this can be done many ways (pico then chmod) for example. Other servers will have web-based mechanisms for these purposes. Finally, some ftp programs also have this ability.

1. In the directory you want to redirect, create (or edit if it already exists) the .htaccess file. Note the leading dot which is required.

2. In one complete line, without any additional line feeds, enter the direct command.

The redirect command has the following format: redirect status old-url new-url
– Status is optional and may be one of the following:

  • permanent – (301) resource has moved permanently.
  • temp – (302). resource has moved temporarily.
  • seeother – (303) resource has been replaced.
  • gone – (410) resource has been permanently removed. (When this status is used the new-url argument should not be used.)

3. Save the file

4. If you created the file, you may need to set the permissions to be web readable. If you have access to the chmod command then type chmod 664 .htaccess.

So in my example, my .htaccess file would contain the line
redirect permanent /techrx/test http://tech-recipes.com/

David Kirk
David Kirk
David Kirk is one of the original founders of tech-recipes and is currently serving as editor-in-chief. Not only has he been crafting tutorials for over ten years, but in his other life he also enjoys taking care of critically ill patients as an ICU physician.
RELATED ARTICLES

13 COMMENTS

LEAVE A REPLY

Please enter your comment!
Please enter your name here

- Advertisment -

Most Popular

Recent Comments

Cleveland Furia on How to Clear Google Activity
Sid Wohlfarth on How to Clear Google Activity
Riley Magsayo on How to Clear Google Activity
สมัครรับเครดิตฟรี ทันที on How to improve Remote Desktop Protocol Performance
Neal Wangstad on How to Clear Google Activity
Slavcho Andov on How to install Ubuntu
Slavcho Andov on How to fix bad sectors
Sheraz Ali on How to Backup Android