Forum Moderators: phranque
I used to have a lot of .htaccess files scattered around and thus the server had a bit of extra load due to having to override etc.
Now there are just two .htaccess files and I think it would be even better to have them in the httpd.conf file.
My question is: Can anything which is in the .htaccess file go in httpd.conf?
Here's the .htaccess from the root of the home dir:
###############################################
#
# .htaccess in /home/mysite/public_html
#
#block bad guys
<Files ~ "^.*$">
order allow,deny
allow from all
deny from nnn.nnn.nnn.nnn
</Files>
rewriteEngine on
rewriteCond %{HTTP_USER_AGENT} ^LinksManager [OR]
rewriteCond %{HTTP_USER_AGENT} ^EmailSiphon [OR]
RewriteCond %{QUERY_STRING} ^(.*)gratishost
RewriteRule ^.*$ - [F,L]
# prevent access from santy webworm a-e
RewriteCond %{QUERY_STRING} ^(.*)highlight=\%2527 [OR]
RewriteCond %{QUERY_STRING} ^(.*)rush=\%65\%63\%68 [OR]
RewriteCond %{QUERY_STRING} ^(.*)rush=echo [OR]
RewriteCond %{QUERY_STRING} ^(.*)wget\%20
RewriteRule ^.*$ [127.0.0.1...] [R,L]
# prevent pre php 4.3.10 bug
RewriteCond %{HTTP_COOKIE}% s:(.*):\%22test1\%22\%3b
RewriteRule ^.*$ [127.0.0.1...] [R,L]
# prevent perl user agent (most often used by santy)
RewriteCond %{HTTP_USER_AGENT} ^lwp.* [NC]
RewriteRule ^.*$ [127.0.0.1...] [R,L]
RewriteCond %{HTTP_HOST} ^mysite\.co\.uk
RewriteRule ^(.*)$ http://www.mysite.co.uk/$1 [R=permanent,L]
RewriteCond %{SCRIPT_FILENAME} ([^/]+)\.wmv$
RewriteRule ^.*$ http://www.mysite.co.uk/course1/course1.html [R=permanent,L]
######################################################
As you can see there is a fair mix of different things going on there.
Can they all go in the httpd.conf file?
How does it fit in?
I guess I just create
<directory "/home/mysite/public_html">
</directory>
and paste the file between the directory tags?
In order to stop apache for scanning for .htaccess files in every dir I then need to add:
<directory />
AllowOverride None
</directory>
Does that sound right?
[edited by: jdMorgan at 2:04 pm (utc) on Sep. 15, 2005]
[edit reason] Disabled smilies to clarify code. [/edit]
RewriteRule ^(.*)$ http://www.mysite.co.uk/$1 [R=permanent,L]
RewriteRule [b]^/([/b].*)$ http://www.mysite.co.uk/$1 [R=permanent,L]
RewriteCond %{HTTP_USER_AGENT} ^lwp.* [NC]
RewriteRule ^.*$ http://127.0.0.1/ [R,L]
RewriteCond %{HTTP_USER_AGENT} ^lwp [NC]
RewriteRule ^.*$ - [F]
Also, the pattern in
RewriteCond %{SCRIPT_FILENAME} ([^/]+)\.wmv$
Jim
as for this line:
RewriteCond %{SCRIPT_FILENAME} ([^/]+)\.wmv$
I think that is the solution to a problem I had a year ago. It solves the problem of users directly linking to a movie file whereas they should be reading the html instructions and playing the movie from that page.
What it does is to redirect requests for the wmv to the html, however, if the wmv is called directly from the page then no redirect (else endless loop). Well it works anwyay.