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
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
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
located inOn a system with a default build of Apache you may have to place these at the end of the
file located inIn 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.
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.