Jul
03

How to write a simple php redirect script

php, web design       Trackback

If your looking to redirect users to a different page on your site or need to put together an affiliate link then you’ll be happy to know that you can easily achieve this using php, its not complex and it works in all browsers. The code is as follows.

<?php
header( ‘Location: http://www.yourdomain.com/new_page.html’) ;
?>

Simply change the http://www.yourdomain.com/new_page.html with your url or affiliate link. The only thing to watch however is not to send any html to the browser before the script block otherwise it won’t work. So for example, if you used something like this in your page it would fail.

<html>
<head>
<?php
header( ‘Location: http://www.yoursite.com/new_page.html’ ) ;
?>
</head>
<html>

To be on the safe side I create a completely blank php page and simply add the php script block and nothing else. If you want to check that your redirect script is working then the best way is to use this headers tool from SEO Consultants. Enjoy!

Share and Enjoy:

These icons link to social bookmarking sites where readers can share and discover new web pages.
  • Digg
  • del.icio.us
  • StumbleUpon
  • DZone
  • DesignFloat
  • Technorati
  • Reddit

No Comments

No comments yet.

Comments RSS Feed    TrackBack URL

Sorry, the comment form is closed at this time.

Sponsors

Wordpress Themes Market
Woo Themes
Hostgator
Revolution Wordpress Theme

Categories