Thursday 3 November 2016

Published 04:15:00 by with 0 comment

How to redirect php page header location RewriteRule

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:
1
2
3
<?php
header('Location: http://www.fluxntech.com');
?>
You only have to change http://www.fluxntech.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:
1
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:
1
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.
      edit

0 comments:

Post a Comment