Create Account
Sign In

PHP Redirection (Header and URL Rewrite) - redirect php page header location RewriteRule


PHP Redirection (Header and URL Rewrite) - redirect php page header location RewriteRule PHP Redirection (Header and URL Rewrite) - redirect php page header location RewriteRule The 09/08/2010 at 19:01:59
Rating: 4/5
Keywords: php redirection header location URL Rewriting RewriteEngine http redirection location php script trick redirect a page change location destination page

Hi,
In this php trick, I will show you two ways to make redirections. The first will be in PHP using the header function and the second one will use the URL Rewriting using the .htaccess file.

Method #1

This way is dynamic because you can execute a php code before. Be sure that there is no (X)html code or any echo before the redirection:
<?php
header('Location: http://www.webestools.com');
?>
You only have to change http://www.webestools.com by the URL of the destination page.

Method #2

This way use URL Rewriting, so you have to create a .htaccess file and he must contain the following code in the beginning:
RewriteEngine on That will activate the URL Rewriting. In the following code, when someone go to mypage.html, he will be automatically be redirected to mypage2.html:
RewriteRule ^mypage\.html$  /mypage2.html [R] You have to add the code above in you .htaccess file. mypage.html don't need to realy exist in the server to make the redirection.

I hope this trick will be useful.

Similar Scripts and Tutorials

Javascript redirection with a timeout - timed redirect js timeout Javascript redirection with a timeout - timed redirect js timeout Custom 404 error pages - php url rewrite ErrorDocument not found htaccess Custom 404 error pages - php url rewrite ErrorDocument not found htaccess PHP Script execution timer - loading page microtime timer execution time PHP Script execution timer - loading page microtime timer execution time Simple PHP Forum Script - php forum easy simple script code download free php forum mysql Simple PHP Forum Script - php forum easy simple script code download free php forum mysql Members Area System in php mysql - members users system area log sign Members Area System in php mysql - members users system area log sign