Register

Redirects

A place to discuss all things about Blogging & Blogging Platforms
Posts: 253
Joined: Tue Nov 08, 2016 3:13 am

Redirects

Postby danni » Thu Feb 23, 2017 4:07 am

Here are some common redirects that are used almost often my webmasters and site owners. So, decided to provide the codes of them.

PHP Single Page Redirect

You have to insert this code in index.php file.

<?php
header("HTTP/1.1 301 Moved Permanently");
header("Location: http://www.newdomain.com/page.html");
exit();
?>


PHP Canonical Redirect

This add or removes the 'www' prefix of your domain.

<?php
if (substr($_SERVER['HTTP_HOST'],0,3) != 'www') {
header('HTTP/1.1 301 Moved Permanently');
header('Location: http://www.'.$_SERVER['HTTP_HOST']
.$_SERVER['REQUEST_URI']);
}
?>


.htaccess Singe Page Redirect

Insert this code in your .htaccess file

Redirect 301 /old/oldpage.htm /new/http://www.domain.com/newpage.htm


.htaccess Canonical Redirect

Options +FollowSymlinks
RewriteEngine on
rewritecond %{http_host} ^domain.com [nc]
rewriterule ^(.*)$ http://www.domain.com/$1 [r=301,nc]

Posts: 94
Joined: Mon Nov 28, 2016 5:22 am

Re: Redirects

Postby bpatel » Sat Feb 25, 2017 4:07 am

Nice post and thanks. I needed the .htaccess updates.

Posts: 130
Joined: Wed Jan 11, 2017 4:41 am

Re: Redirects

Postby adam_jones » Tue Feb 28, 2017 6:20 am

Great information about redirects.Thanks.

Posts: 319
Joined: Fri May 25, 2018 5:45 am

Re: Redirects

Postby richardmsmith » Fri Jul 06, 2018 6:49 am

Thanks for sharing redirects code in php.
Please share types of redirects in php or how many way can we write code for redirects.

Return to Blog Management & Promotion

Who is online

Users browsing this forum: No registered users and 1 guest