2

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.

2 Answers 2

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>
0

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

1
  • 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, 2011 at 15:13

You must log in to answer this question.