Take the 2-minute tour ×
Server Fault is a question and answer site for system and network administrators. It's 100% free, no registration required.

I came across an article titled "Efficient 301 Redirects."

For example, if you are trying to redirect your site from www to non-www domain, the article suggests that when compared to this .htaccess/httpd.conf rule:

<IfModule mod_rewrite.c>
  RewriteEngine On
  RewriteCond %{HTTP_HOST} ^www.domainname\.com$ [NC]
  RewriteRule ^(.*)$ http://domainname.com/$1 [R=301,L]
</IfModule>

this would be a more efficient 301 redirect (although only slightly):

<IfModule mod_alias.c>
  Redirect permanent / http://domainname.com/
</IfModule>

Question: Is the latter rule really efficient (even slightly)?

share|improve this question
    
Indeed. However, I'm unsure why you can't simply add the second rule after enabling mod_alias. –  Pothi Sep 22 '13 at 2:16

1 Answer 1

up vote 2 down vote accepted

to answer your question: yes, it is, and the article also states why:

... by using Redirect directive of Apache and return directive of Nginx, we can effectively avoid doing any capturing or matching at all and thus we can completely avoid evaluation of a regular expression.

it's about simply skipping some steps of evaluation.

i'd like to see perftest against this solution/tweaks

share|improve this answer
2  
I don't know about specific performance benchmarks... But the apache folks make the recommended (redirect > rewrite) approach quite clear: httpd.apache.org/docs/2.2/rewrite/avoid.html#redirect –  lVlint67 Sep 23 '13 at 7:53

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.