Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Speed implications of using Redirect vs RewriteRule

I'm curious to know if there is any difference in speed between RewriteRules and Redirect within a .htaccess rule on Apache.

To my mind, RewriteRules can often be complex regex expressions which I assume have overhead (even if it's incredibly small) compared to Redirect that would be simple string matching(?)

So, if I had:

RewriteRule ^mytestpage\.html$ http://www.google.com [R=301, QSA]

vs

Redirect 301 /mytestpage\.html http://www.google.com/

I'm probably never going to notice a difference, but what if I had 1000 unique redirects? or 10,000? Would it be adventagous to use one over the other?

like image 812
Douglas Radburn Avatar asked Sep 02 '25 15:09

Douglas Radburn


1 Answers

The speed implications of using either is negligible and you won't notice a difference. That being said, you should use the right tool for the job.

Doing a simple redirect, you should use a Redirect instead of using Mod_Rewrite. That example is something a Redirect should take care of. When you need to start doing more complex things you can think about using Mod_Rewrite.

Even with 1000 or 10,000 redirects you're not really going to notice a big difference. However it will use more RAM. Probably a few MB's if that.

So to answer your question, it really wont have a real impact but use the right tool for the job.

This should help.

When not to use mod_rewrite

like image 70
Panama Jack Avatar answered Sep 05 '25 10:09

Panama Jack