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


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.

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

PHP Canonical Redirect

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

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

.htaccess Singe Page Redirect

Insert this code in your .htaccess file

Redirect 301 /old/oldpage.htm /new/

.htaccess Canonical Redirect

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

Posts: 84
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: 116
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 0 guests