How to redirect a Web URL

There are different methods to redirect a Web URL or Page to a different URL or Page. Redirection cab be done using HTML , JavaScript,  Apache or PHP.

In this post we will look at all different ways.

HTML redirect

Using meta refresh tag of HTML.

 <meta http-equiv="refresh" content="0;URL='http://example.com/'" />    

PHP redirect

Using PHP header function. Its sends a 302 redirect. Its must be used at top of page before any HTML tag or PHP code.

 <?php header('Location: http://www.example.com/'); ?> 

JavaScript redirect

window.location object can be used to redirect to any URL ot page.

 <script> window.location.replace("http://www.example.com/"); </script>

jQuery redirect

 <script> $(location).attr('href', 'http://www.example.com/') </script>

Apache .htaccess redirect

 Redirect permanent /oldurlorlocation.com http://newurl.com

There are many ways to redirect in JavaScript and jQuery. There are most commonly used methods.

0 replies

Leave a Reply

Want to join the discussion?
Feel free to contribute!

Leave a Reply

Your email address will not be published. Required fields are marked *