Search The Hostwinds Guides Knowledge Base

Set a Temporary (302) Redirect Using .htaccess

There are two types of redirects, a permanent and temporary redirect. We will be taking a look at temporary redirects. If you’d like to learn how to utilize a permanent redirect, please consult our guide which covers this in detail: Set a permanent (301) redirect using .htaccess

How do I create a temporary redirect?

The first thing you’ll need to do (if you haven’t already) is create an .htaccess file. If you’re not certain how to create an .htaccess file no worries we have you covered with our guide: Creating and editing an .htaccess file. Once the .htaccess file has been created you’ll need to edit the contents of this file using the method that best suits your needs. Typically the options available to edit your .htaccess file are as follows.

 

  • Use a file editor built into a file manager such as cPanel’s file manager
  • Download or create the .htaccess file locally and then re upload it via FTP
  • Edit the file directly using a text editor via SSH

 

Regardless of the method that you’re using, the code that you’ll be adding is the same. To redirect your entire website to a different URL you’d use the following entry in the .htaccess file:

 

 

The above will redirect your current website to a new site of your choosing, this is excellent if you’re rebuilding your site and you’d like to direct visitors to a temporary site or landing page. To redirect a portion of your site you’d place the following code in your .htaccess file:

 

 

Once you’re satisfied save the file and the redirect should be in place!