Redirect users to a new Page

There are various methods we can use to redirect users to different URL. Let's have a look at codes below with just one goal.

HTML Meta Refresh Tag

Most common way to redirect users to another location is using HTML refresh meta tag, just have this code placed within the <head></head> section of your HTML page :
HTML
  • 1
<meta http-equiv="refresh" content="0;URL=http://www.sanwebe.com" />

Javascript Location

And here is another method using Javascript window.location, only downside is if browser doesn't support Javascript, this code will fail to redirect user to new location:
JS
  • 1
  • 2
  • 3
  • 4
<script type="text/javascript"> //Will take you to sanwebe.com window.location.href = 'http://www.sanwebe.com'; </script>

PHP Header

We can use PHP header to redirect user to new URL easily, but remember there must be NO other output before this code, such as echo code which will trigger "headers already sent" error.
PHP
  • 1
  • 2
  • 3
  • 4
  • 5
<?php // This results in an error. // The output above is before the header() call header('Location: http://www.example.com/'); ?>

Perl Location

Here's perl code to redirect user to sanwebe.com.
PERL
  • 1
  • 2
  • 3
#!/usr/bin/perl $url = "https://www.sanwebe.com/"; print "Location: $url\n\n";
    New question is currently disabled!