How Do I Redirect Url With PHP Script

Add Tool

How Do I Redirect Url With PHP Script

How Do I Redirect Url With PHP Script

How do I redirect with PHP script? How can I use a PHP script to redirect user from the url they entered to a different web page/url? Yes, you can do these adding a small php snippets in your header section. Here I have share a small PHP (PHP Hypertext Preprocessor) snippets which will help you to redirect your url to another url By using PHP's "header" function. The header function is a PHP specific function and can not be used outside of PHP.

Redirect One Page to Another

 header("HTTP/1.1 301 Moved Permanently");


<?php header("Location:", true, 301); ?>

Redirect from file to directory root

if(isset($_SERVER['HTTPS']) and 'on' === $_SERVER['HTTPS']) {
    $location = 'https://';
} else {
    $location = 'http://';
// Get the servers base URL
$location .= $_SERVER['SERVER_NAME'] . '/';
// Get the current URI without a file name in it
$location .= dirname($_SERVER['REQUEST_URI']) . '/';
header('Location: ' . $location);

I took the PHP tags so don’t forget to remove those in if you need to.

Thanks Brad Knutson for this important PHP Redirect snippets.

Tags: php redirect header location, location header in php, php header location permanent redirect, php redirect without header location, php header location 302 redirect, header location relative, php header redirect to self, header location php not working, p

About Masum Billah

How Do I Redirect Url With PHP Script 1stWebSuite website seo tool is a free website ranking tool site provides a lot of on page and off page seo useful tools for you. On this site, we have a large number of website ranking tools


Discuss about: How Do I Redirect Url With PHP Script