Forum Moderators: phranque

Message Too Old, No Replies

Best method for a 301 domain redirection

I just need a 301 to a new domain. What to use for best performance?

         

bwakkie

2:07 pm on Apr 14, 2009 (gmt 0)

10+ Year Member



Hi all,

I have 2 domain names for one website

old-domain.com
new-domain.com

I only want everyone to use new-domain.com

What is best performance wise?

A) Use html refrech meta tag:

<META HTTP-EQUIV="Refresh" Content="0; URL=http://www.new-domain.com/dir1/">

B) use mod_cgi with:
#!/usr/bin/perl
print "Status: 301 Moved\r\n" .
"Location: http://www.new-domain.com/\r\n" .
"\r\n";

C) Use php header
<?php
header("Location: http://www.new-domain.com/");
?>

D) use mod_alias

Redirect permanent / http://www.new-domain.com/

E) use mod_rewrite

RewriteEngine on
RewriteCond %{HTTP_HOST} ^old-domain.com
RewriteRule ^(.*)$ http://www.new-domain.com/$1 [R=permanent,L]

I guess Redirect? option D

What do you think?

Cheers,
Bastiaan

jdMorgan

3:02 pm on Apr 14, 2009 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Solutions D or E, because the "action" occurs sooner, and relies on built-in server functions.

Solution D will work if the www and non-www domains resolve to different <VirtualHost> configuration containers or .htaccess files. If they do not, then you will have to use solution E, because solution D will loop recursively on requests for the "www" domain.

Jim

g1smd

8:21 pm on Apr 14, 2009 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



Option C is a 302 redirect unless you add another line before it to ensure it becomes a 301 redirect.

I would use E because you shouldn't mix (Mod_Auth redirects) and (Mod_Rewrite rewrites and redirects) in the same .htaccess file.

There are times when C is the best thing to use.

I would never use A, as it is too risky.

bwakkie

7:40 am on Apr 15, 2009 (gmt 0)

10+ Year Member



PS> I never use .htaccess files as they give overhead in every request to the server and therefore its is best to avoid useing them:

AllowOverride None

in your (httpd¦apache2?).conf

jdMorgan

1:01 pm on Apr 15, 2009 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



As most Web sites today are on shared name-based virtual hosting, many Webmasters have no other options but to use .htaccess. So we get a lot of discussion here about .htaccess files, despite the fact that the .htaccess code must be re-compiled for each HTTP request and thereby introduces some overhead.

However, any code that is executed on the server side, including PHP, PERL, etc. introduces *some* overhead, and the question is, "Is the execution overhead worth the benefit?" If it is, then let the server do the work and don't worry about it -- except to make a good attempt to use efficient coding and efficient methods to implement the the functions you need.

When putting your code into http.conf, apache2.conf, or conf.d is an option, then the only significant advantage to putting code into .htaccess is that you don't have to re-start the server after making changes to that code. So using .htaccess is often useful for testing. But having debugged the code, moving it into the server configuration is certainly worthwhile -- if you have that option.

Jim