This site utilizes JavaScript to function correctly. Looks like it's disabled on your browser. Please enable it for your best experience.

For instructions on enabling JavaScript, click here

Skip to main content

Just Host Web Hosting Help

How To Code a PHP Redirect - PHP Header Redirect

Redirection in PHP can be done using the header() function. To setup a simple redirect, simply create an index.php file in the directory you wish to redirect from with the following content:
            < ?php header("Location: http://www.redirect.to.url.com/"); ?>
            
Where 'http://www.redirect.to.url.com/' is the URL you wish the users to be redirected too. This can also be a file, like so:
            <?php header("Location: anotherDirectory/anotherFile.php"); ?>
            
Files can be of any type including but not limited to HTML, python, php, cgi, perl, and compiled cgi programs.
Knowledgebase Article 933,268 views bookmark tags: header location php redirect redirects


Was this resource helpful?

Did this resolve your issue?


Please add any other comments or suggestions about this content:





Recommended Help Content

Redirects allow you to make a specific web page redirect to another page and display the contents of that page. Learn how to setup a Permanent (301 or Termporary (302) redirects.
Video "How-to" Tutorial 600,284 views tags: cpanel cpanelutilities domain forward redirect

The redirection of www.yourdomain.com/default.html or index.html to http://www.yourdomain.com/index.php?act=whatever redirects it to http://www.yourdomain.com/index.php%3fact=whatever In other words,
Knowledgebase Article 1,035,302 views tags: htaccess messing mod php redirect redirects rewrite variable variables

How do I create a redirect?
Knowledgebase Article 655,331 views tags: htaccess redirect redirects

Related Help Content

If suddenly when you go to your page, you get nothing on the page. You can still get HTML to display, just not PHP. To serve HTML pages to browsers, we don't associate the Apache processes with your 2
Knowledgebase Article 190,203 views tags: blank page php

How do I view the php information page?
Knowledgebase Article 199,922 views tags: php phpinfo

How do I perform a URL redirect/rewrite using the .htaccess file?
Knowledgebase Article 1,935,361 views tags: htaccess redirect rewrite url

Executing php code within a HTML document
Knowledgebase Article 234,232 views tags: addhandler addtype handler mime parse php sethandler

Why do scripted e-mails come from &amp;lt; username@just###.Justhost.com &amp;gt; when I have specified otherwise?
Knowledgebase Article 467,782 views tags: email forms header php script scripted sendmail

This article will explain how to add a PHP handler to your .htaccess files. This is useful if you want to customize the version of PHP that runs your PHP files.
Knowledgebase Article 404,775 views tags: htaccess php

I need an EPP authorization code to transfer my domain to another registrar.
Knowledgebase Article 418,665 views tags: auth authorization code domain epp transfer

How do I display the Internet email header?
Knowledgebase Article 545,220 views tags: email header mail

** Google ad credits are only available to customers in the United States, Canada, and the United Kingdom at this time.

¹ VAT (Value Added Tax) is not included in our advertised price and will be charged separately and itemized on invoices and billing information. Standard VAT rates based on EU Member State regulations may apply. Learn more.