pepe
pepe

Reputation: 9919

.htaccess for 301 redirect: which syntax is best?

I am permanently redirecting my website

http://www.oldsite.com

to

http://newsite.com/blog

Is there a difference between using

Redirect 301 / http://newsite.com/blog/

or

RewriteEngine On 
RewriteRule ^(.*)$ http://newsite.com/blog/$1 [R=301,L]

Any reason I should use one over the other?

Upvotes: 2

Views: 4629

Answers (2)

Ulrich Palha
Ulrich Palha

Reputation: 9539

I believe the performance difference between the two would be imperceptible to a user.

However, assuming that all of the URLs on the old blog site cleanly map to the new site, then I would recommend using the second method.

If you use the first method, all links to your old blog posts will end up on the home page of your new site, which is not a great experience for users who may have bookmarked links etc.

If you care about SEO, then its the same story, all of your page rank will go from your old blog posts to your new site home page.

Upvotes: 1

jmkeyes
jmkeyes

Reputation: 3781

The first uses Apache's internal redirection engine to direct all requests to / to http://newsite.com/blog with a 301 Moved Permanently response code.

The other loads the Apache rewriting engine and rewrites all of the incoming requests that match ^(.*)$ to http://newsite.com/blog/ (appending the matched part of the request URI to the target URI) with a 301 Moved Permanently response code, like the former.

The difference? The former rewrites everything to http://newsite.com/blog/ regardless of the request, and the second takes into account the request URI rewriting it as specified. The first is also somewhat faster than the second because it does not load the rewriting engine, does not introspect the request itself, and (depending on the AllowOverride setting) does not have to look up and load .htaccess files.

Upvotes: 3

Related Questions