Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

.htaccess redirect performance

Are htaccess redirects any slower/put any more strain on Apache than redirects in configuration files? Also, how big can a number of redirects in htaccess get before they start decreasing performance?

like image 659
deadprogrammer Avatar asked Oct 16 '08 16:10

deadprogrammer


People also ask

Does htaccess slow site down?

htaccess files slows down your Apache http server. Any directive that you can include in a . htaccess file is better set in a Directory block, as it will have the same effect with better performance."

What is .htaccess redirect?

Using Redirect in an .htaccess file enables you to redirect users from an old page to a new page without having to keep the old page. For example, if you use index.html as your index file and then later rename index.html to home.html, you could set up a redirect to send users from index.html to home.html.

How can I redirect and rewrite my urls with an .htaccess file?

Use a 301 redirect . htaccess to point an entire site to a different URL on a permanent basis. This is the most common type of redirect and is useful in most situations. In this example, we are redirecting to the "example.com" domain.

What is the purpose of using the .htaccess file?

. htaccess files (or "distributed configuration files") provide a way to make configuration changes on a per-directory basis. A file, containing one or more configuration directives, is placed in a particular document directory, and the directives apply to that directory, and all subdirectories thereof.


2 Answers

Yes, it slows the server because it has to access the file each time a resource in that directory or any subdirectory thereof is accessed.

The amount of redirects is not relevant, because the main performance hit is the file access itself. This within reasonable constraints (ie a 5 Kb htaccess file will take more or less the same time to be parsed than a 1 Kb one, different story is a 1Mb htaccess, though I've never seen that monstrosity and hope I never will)

like image 147
Vinko Vrsalovic Avatar answered Oct 20 '22 05:10

Vinko Vrsalovic


While it's true that the .htaccess is parsed on each request, and is thus technically slower than putting your rules in the main config file, in reality it doesn't matter. The apache configuration engine is fairly optmized C code that's embedded in the web server. Unless you're only serving small static files with no database accesses at all, the extra overhead of .htaccess and redirects is negligible.

Modern processors are so fast that you'd really have to be doing a massive amount of traffic to worry about this. If you're doing this much traffic, and since it's all static content, go ahead and buy yourself a second server to share the load.

like image 24
bmdhacks Avatar answered Oct 20 '22 04:10

bmdhacks