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.

I have two htaccess rules that I would like to move to httpd.conf because I hear that's better for performance. I tried just copy-pasting them into httpd.conf but it doesn't use the same syntax I suppose because it didn't work. Can someone please show me what the httpd.conf equivalent of these two .htaccess rules will be:

# DISABLE HOTLINKING
RewriteEngine on
# Options +FollowSymlinks
RewriteCond %{HTTP_REFERER} !^$
RewriteCond %{HTTP_REFERER} !^http://(www\.)?mysite.com/.*$ [NC]
RewriteRule \.(gif|jpg|jpeg|png|js)$ - [F]


# PREVENT ALL ACCESS TO THIS FILE
<files admin.php>
 order allow,deny
 deny from all
</files>

Many thanks.

share|improve this question

2 Answers 2

just put them as it is.

.htaccess is exactly httpd.conf for that directory. if you want to restrict to only that directory, just put it inside like this:

<Directory /path/to/your/directory>
# DISABLE HOTLINKING
RewriteEngine on
# Options +FollowSymlinks
RewriteCond %{HTTP_REFERER} !^$
RewriteCond %{HTTP_REFERER} !^http://(www\.)?mysite.com/.*$ [NC]
RewriteRule \.(gif|jpg|jpeg|png|js)$ - [F]


# PREVENT ALL ACCESS TO THIS FILE
<files admin.php>
 order allow,deny
 deny from all
</files>
</Directory>
share|improve this answer

Putting configuration rules in httpd.conf has no real effect on performance vs. .htaccess unless you have large numbers of them.

share|improve this answer
    
That's incorrect. At minimum, you're triggering an lstat(2) on every access of every file, since Apache needs to ensure that the file hasn't changed since it last parsed it. And I'm pretty sure--though admittedly not entirely sure--that Apache doesn't cache htaccess files, which means you're actually doing an open(2) and a parse run for every single access. The performance gains from moving htaccess into your base Apache config might not be enormous, but they definitely are extant, and can be pretty significant on a large site or when the htaccess in question is very complicated. –  BMDan Apr 10 '11 at 15:13

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.