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

How and where do I put my mod_rewrite rules in the httpd configuration so that they're only parsed once at startup instead of each time a file in my web directory is read.

Additional info:

  • assuming all scripts work in .htaccess file
  • RHEL4 running Apache 2.0.52
  • multiple sub/domains on the the machine

Thanks

share|improve this question
add comment

4 Answers 4

up vote 2 down vote accepted

I'm not sure to have understand the question but if the question is "I currently have rewrite rule in a .htaccess file and want to put them in the whole apache configuration." you have to add a <Directory /path/to/directory/where/htaccess/is> directive in the apache configuration and put the content of the .htaccess file into it.

If .htaccess is in /srv/web/site1/folder1/ then add the following in the apache config file

<Directory /srv/web/site1/folder1>
Paste content of .htaccess here
</Directory>
share|improve this answer
    
In a Redhat system that central directory would be /etc/httpd/conf.d. –  memnoch_proxy Jan 31 '10 at 6:16
add comment

The answers are all here - they're just not all bundled together.

As memnoch_proxy states:

"Rules modified in .htaccess files are read on every request. /etc/httpd/httpd.conf and /etc/httpd/conf.d/* are not. I trigger new changes to those files using service httpd reload which sends a SIGUSR1 to workers to restart gracefully."

So it sounds to me like you're using .htaccess files to define your re-write rules which apply to your site and/or folder structure.

In order to prevent the rules being re-read and re-interpretted every time the directory or page is accessed the rules need to be placed within the central Apache configuration files for your website.

The location of these rules varies depending on how the systems administrator has laid out the system; on a Red Hat Enterprise Linux environment I would recommend you place them in their a file named

rewrite-rules.conf
located in
/etc/httpd/conf.d

On a system with a default build of Apache you may have to place these at the end of the

httpd.conf
file located in
/usr/local/apache/conf

share|improve this answer
add comment

In your httpd.conf file, add something like "include modrewrite.conf". Then in the moderewrite.conf file, add the rewrite rules.

Also ensure you've include the mod_rewrite module if not compiled in.

share|improve this answer
    
On Redhat systems the httpd.conf file is pretty generic and I wouldn't configure vhost settings in it. Define a vhost in /etc/httpd/conf.d instead. –  memnoch_proxy Jan 31 '10 at 6:18
add comment

RewriteRules are processed every time a resource on your server is accessed that the rules relate to. Regardless of where the rules are placed, they will be parsed every time.

However, if you mean that you do not like the overhead of .htaccess being read from the disk on every resource request, then radius' answer is what you want, with the additional obvious instruction of then removing the .htaccess file after placing its contents in the main apache configuration file.

share|improve this answer
    
Rules modified in .htaccess files are read on every request. /etc/httpd/httpd.conf and /etc/httpd/conf.d/* are not. I trigger new changes to those files using service httpd reload which sends a SIGUSR1 to workers to restart gracefully. –  memnoch_proxy Jan 31 '10 at 6:20
add comment

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.