Originally this article discussed the 301 redirect, but as I moved it from services-seo.net to janhvizdak.com, I decided to update the content.
.htaccess 301 Redirect - New Domain Redirect
This is a good choice when you buy a new domain for your old one and you simply copied the source files, so everything in URL's is same except for the domain name. In this case simply put these lines into your
.htaccess file:
Options +FollowSymlinks
RewriteEngine on
rewritecond %{http_host} ^old_domain.tld [nc]
rewriterule ^(.*)$ http://www.new_domain.tld/$1 [r=301,nc]
.htaccess 301 Redirect - Single Page Redirect
Of course, usually you aren't changing domains each month, so a redirect that redirects one page to it's new URL is needed more often. It's easy too, into
.htaccess put this line for instance:
redirect 301 /old_page.html http://www.yourdomain.tld/newpage.html
Bear in mind that using some special symbols such as
? may cause problems and if you aren't .htaccess expert, use PHP redirects instead.
PHP 301 Redirect
The 301 redirect done via
PHP is what I like the most as things are very easy (unlike .htaccess expressions). Of course, things may get complicated in PHP too and not everything can be resolved via PHP, but anyway I'm using it very often. Here is the PHP code:
<?php
Header("HTTP/1.1 301 Moved Permanently");
Header("Location: http://www.newuri.tld");
exit();
?>
Happy redirecting ;) !