Thread Rating:
  • 0 Vote(s) - 0 Average
Share Thread:
Redirects
#1
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.

Quote:<?php
header("HTTP/1.1 301 Moved Permanently");
header("Location: <!-- m --><a class="postlink" href="http://www.newdomain.com/page.html">http://www.newdomain.com/page.html</a><!-- m -->");
exit();
?>

PHP Canonical Redirect

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

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

.htaccess Singe Page Redirect

Insert this code in your .htaccess file

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

.htaccess Canonical Redirect

Quote:Options +FollowSymlinks
RewriteEngine on
rewritecond %{http_host} ^domain.com [nc]
rewriterule ^(.*)$ <!-- m --><a class="postlink" href="http://www.domain.com/$1">http://www.domain.com/$1</a><!-- m --> [r=301,nc]
Reply
#2
Nice post and thanks. I needed the .htaccess updates.
Reply
#3
Great information about redirects.Thanks.
Reply
#4
Thanks for sharing redirects code in php.
Please share types of redirects in php or how many way can we write code for redirects.
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)
[-]
Ad

[-]
Top Articles
100+ Social Bookmarking Sites List
55+ Image Submission Sites List

[-]
Recent Posts
Growth Matrix Reviews - Warning! Do NOT Buy Until Knowing This!
Growth Matrix Reviews:>> DISCRIPTION =>> Growth Matrix Reviews is an enhance...RoseBenif — 07:48 AM
Empowering the Skills on Kafka Training with Gologica’s IT Expert
Gologica Offers Kafka Online training, it will help you to get  know  more about Apache K...Naresh1 — 07:35 AM
Nike presenterar den Barcelona-inspirerade Phantom 'Barna'-kollektione...
Nike firar sin koppling till den pulserande staden Barcelona med Phantom 'Barna'-kollekti...fotbollsskorfor — 07:11 AM
PUMA představuje druhé vydání kolekce NJR Creativity Collection, inspi...
PUMA se vrací s druhým vydáním NJR Creativity Collection, pulzující řadou inspirovanou el...kopackycz — 07:08 AM
https://www.facebook.com/slimxmederfahrungen/
SlimXMed Erfahrungen SlimXMed Erfahrungen Weight loss is everyone’s hassle those da...PerezFanders — 07:05 AM

[-]
Follow us on Facebook