Welcome to WebmasterWorld Guest from 34.204.168.57

Forum Moderators: Ocean10000 & phranque

Message Too Old, No Replies

Rewrite definition in httpd.conf /subdir or htaccess

     
4:06 pm on Aug 26, 2003 (gmt 0)

New User

10+ Year Member

joined:June 3, 2003
posts:35
votes: 0


I read: "Also, if a rewrite is in a subdirectory, then it affects performance in that subdirectory only"
I might aply mod_rewrite in htaccess,
but I am wondering if I might use it for maintanance reasons in a subdir of httpd.conf
<VirtualHost .........>
Rewrite on
RewriteRule ^\/(.*)\.html$ /cgi-bin/a-tested.cgi [L]
<Directory /home/www/web111/html/img>
RewriteEngine on
RewriteRule \/img\/(.*)\.png$ "/cgi-bin/b-tested.cgi" [L]
</Directory>
</VirtualHost>
Butin RewirteLog I see only
.. pass through /img/img2test.png

Is there a way to avoid multiple htaccess files and to use a common httpd.conf with subdirs?
Thanks, Maggi

7:18 pm on Aug 26, 2003 (gmt 0)

Preferred Member

10+ Year Member

joined:May 14, 2003
posts:376
votes: 0


yes, maggi, there is... i used to do all my mod_rewrite stuff on my httpd.conf file for all of my virtual domains... however, in doing testing and updating of my rules, i ended up moving them to .htaccess files for easier implementation, faster effectiveness, and much less restarting of my server software...

that last one being the biggest reason for me to move them from httpd.conf to .htaccess...

currently, i have one .htaccess file in the root of each of my domains and that file covers the rewrite rules for all the directories...

note, however, that this is also pertenient to how you have defined your directories in the httpd.conf file... on my system, i have "virtual" directories defined in the httpd.conf file... "virtual" in that you access them by a name different than they carry on the filesystem... in those definitions, i had place restrictions... with those restrictions i had to have seperate .htaccess files for each of them... once i removed those restrictions, i was able to remove the .htaccess files and centralize everything in the main one in the root directory...

another thing to consider for multiple .htaccess files is that the more you have in one, the longer (minute as it may be) it takes top process... also when the system looks in a directory and doesn't find a .htaccess file, the system will back up thru the directory structure looking for one... since the .htaccess file is looked for and processed on each request, it is possible that one could cause a slowdown on their server... how much of a slow down or performance hit is dependant on the size of the .htaccess file and the contents as well as the ordering of the rules...

8:56 pm on Aug 26, 2003 (gmt 0)

Senior Member

WebmasterWorld Senior Member jdmorgan is a WebmasterWorld Top Contributor of All Time 10+ Year Member

joined:Mar 31, 2002
posts:25430
votes: 0


maggi,

> Rewrite on

Should be:
RewriteEngine on

Also, the "escaping" rules for mod_rewrite are a bit different than those for Perl or PHP, so you can leave out the escapes for "/". Parentheses are only required to create back-references, to group characters for quantifiers, e.g. "([0-9]A)+", or to mark the borders of alternatives, e.g. "(A¦B¦C)". Quotes are not needed around the URI substitution string:

RewriteRule /img/.*\.png$ /cgi-bin/b-tested.cgi [L]

The server will traverse the web site's entire directory structure, executing each .htaccess file it encounters as it works its way down to the requested resource. Lower-level .htaccess files (executed later) can therefore override (replace) options set by higher-level .htaccess files. But if a higher-level .htaccess file redirects a request before it gets to a given lower-level .htaccess file, then that lower-level .htaccess file will not be processed.

As wkitty42 says, you may want to develop and test your rewrite rules in .htaccess, and then move them up to httpd.conf once they are working. This saves on server restarts, but does require you to modify your rules to account for the differences between the .htaccess and httpd.conf contexts.

Jim