One of the most powerful and complicated aspects of Apache is the mod_rewrite module. As its name implies, mod_rewrite provides the ability to rewrite URIs.

Although this feature does not necessarily represent a significant performance problem, for each rule that matches and each URI that must be rewritten, system resources are expended. The key is to try to avoid processing URIs too many times and to keep away from the URIs that you don't need to process.

One way of addressing this problem is to use the [L] option. This option tells Apache that it has reached the last rule it should apply to the given URI. That is, no further rules are processed. Unfortunately this is not as easy as it seems.

If the rewrite rule does in fact cause a redirection, the new URI is itself processed, and everything starts over again. In many cases you can avoid this with the use of re-write conditions (RewriteCond), so that if the URI matches a given condition, you won't need to process it further.

A related option is the [S] or skip flag. This flag will skip over a given number of rewrite rules. For example, if the URI is not a file (e.g., a directory) you can tell Apache to skip over rules that only apply to files. In other words, you don't avoid the rewrite rules completely, but you reduce the number you need to process.


In your development environment, you might want to have your files loaded with comments, but comment lines are detrimental on live servers. Comments that are structured properly can be removed easily with the use of shell scripts, which means you can comment your files for the testing phase and then remove the comments before you move files to the live server.


The Pareto principle (80:20 rule) applies to web server performance tuning. Implementing many of the concepts described in this article can increase your performance relatively quickly; however, to squeeze out the last bit of advantage, you probably need to spend a lot more time. Depending on the kind of server you run, your mileage will vary.

Buy Linux Magazine

Get it on Google Play

US / Canada

Get it on Google Play

UK / Australia

Related content

  • Optimizing Servers

    Your homepage was just linked by Slashdot, a new email campaign goes out tonight, and you need the database to deliver survey results. We’ll show you how to help your servers survive the strain.

  • Mod_Mono

    Mod_Mono lets you host .NET applications on your Linux Apache 2 server.

  • Light Web Server Alternatives

    Apache has ruled the web since the mid-90s, but not all users are happy with it. Recent competitors Cherokee and Lighttpd offer an uncomplicated alternative for users who are looking for something light.

  • Apache HTTP Server 2.4

    Apache HTTP Server version 2.4 is full of exciting new features. We share a few of them with you.

  • Magic URL

    With a highly secure Linux server, you don't need a fixed IP address to connect over a cellphone network from anywhere on the planet if you have a Magic URL.

comments powered by Disqus
Subscribe to our Linux Newsletters
Find Linux and Open Source Jobs
Subscribe to our ADMIN Newsletters

Support Our Work

Linux Magazine content is made possible with support from readers like you. Please consider contributing when you’ve found an article to be beneficial.

Learn More