Hi all,
I’m cleaning up my .htaccess file and would like to get a second opinion on the below? For example, for the lines marked in red, am I right in thinking that these lines exclude each other and that one set of these (those at the top) are sufficient on their own?
Any other things you would improve?
I’ve changed the domain names for security purposes. The .htaccess file as it stands below works fine.
Many thanks,
# Rewrite enabled
RewriteEngine On
RewriteRule ^([0-9]+)\\.([0-9]+)\\.([0-9]+)\\.([0-9]+)\\.([0-9]+)\\.([0-9]+)\\.phtml$ index.php?id=$1,$2,$3,$4,$5,$6
RewriteRule ^(.+)\\.phtml$ index.php?$1 [L]
# Deny stealing content (no hot linking)
[COLOR="Red"]RewriteCond %{REQUEST_FILENAME} .*jpg$|.*jpeg$|.*gif$|.*png$|.*ico$|.*js$|.*css$|.*txt$ [NC]
RewriteCond %{HTTP_REFERER} !^$
RewriteCond %{HTTP_REFERER} !^http://(.+\\.)?xyz\\.com/ [NC] [OR]
RewriteCond %{HTTP_REFERER} !^http://www.xyz\\.com/.*$ [NC] [OR]
RewriteRule (.*) /nohotlink.php?pic=$1 [R=302,L][/COLOR]
# Improve site page rank
RewriteCond %{HTTP_HOST} ^xyz\\.com
RewriteRule ^(.*)$ http://www.xyz\\.com/$1 [R=permanent]
# Force PHP5
AddType x-mapp-php5 .php
# Media files - 7 days
<FilesMatch "\\.(ico|pdf|flv|jpg|jpeg|png|gif|swf|mp3|mp4)$">
Header set Cache-Control "max-age=302400, must-revalidate, public, no-transform"
</FilesMatch>
# HTML etc. files - 2 hours
<FilesMatch "\\.(html|htm|xml|txt|xsl)$">
Header set Cache-Control "max-age=7200, must-revalidate, public, no-transform"
</FilesMatch>
# JS/CSS files - 1 day
<FilesMatch "\\.(js|css)$">
Header set Cache-Control "max-age=43200, must-revalidate, public, no-transform"
</FilesMatch>
# PHP etc. dynamic files - disabled
<FilesMatch "\\.(pl|php|[sf]?cgi|spl)$">
Header set Cache-Control: "max-age=0, no-store"
</FilesMatch>
# Needed for php extensionless (clear URL) redirect.
Options -MultiViews
# If index or index.php requested, strip and redirect
RewriteCond %{THE_REQUEST} index(\\.php)?
RewriteRule ^index(\\.php)?$ http://www.xyz.com [R=301,L]
# Pass Through the empty request (to be handled as DirectoryIndex)
RewriteCond %{THE_REQUEST} ^[A-Z]{3,9}\\ /?\\ HTTP
RewriteRule .? - [PT]
# Remove PHP extension from links (internally)
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME}.php -f
RewriteRule ^(.+)$ /$1.php [L,QSA]
# Remove PHP extension from links (externally)
RewriteCond %{THE_REQUEST} ^[A-Z]{3,9}\\ /([^.]+\\.)+php\\ HTTP
RewriteRule ^(.+)\\.php$ /$1 [R=301,L]
# Obscure 'php.ini' files (where they exist)
RedirectMatch 404 .*php\\.ini$
# Deny access to file
<Files .htaccess>
order allow,deny
deny from all
</Files>
# eliminate Code Red and NIMDA Virus attacks
redirect /scripts http://www.stoptheviruscold.invalid
redirect /MSADC http://www.stoptheviruscold.invalid
redirect /c http://www.stoptheviruscold.invalid
redirect /d http://www.stoptheviruscold.invalid
redirect /_mem_bin http://stoptheviruscold.invalid
redirect /msadc http://stoptheviruscold.invalid
RedirectMatch (.*)\\cmd.exe$ http://stoptheviruscold.invalid$1
# automatically corect simple speling errors
<IfModule mod_speling.c>
CheckSpelling Off
</IfModule>
# Directory index page
DirectoryIndex index.php index.html index.shtml index.htm
IndexIgnore *
Options -Indexes
# Error pages handling
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule (.php) /error/404.php
ErrorDocument 400 /error/400.php
ErrorDocument 401 /error/401.php
ErrorDocument 403 /error/403.php
ErrorDocument 404 /error/404.php
ErrorDocument 500 /error/500.php
ErrorDocument 501 /error/501.php
ErrorDocument 502 /error/502.php
# Performance tweaks
<IfModule mod_deflate.c>
a2enmod deflate
SetOutputFilter DEFLATE
AddOutputFilterByType DEFLATE text/html text/plain text/css text/javascript application/x-httpd-php application/x-httpd-fastphp application/javascript application/json
AddOutputFilterByType DEFLATE text/xml application/xml text/x-component
DeflateCompressionLevel 9
BrowserMatch ^Mozilla/4 gzip-only-text/html
BrowserMatch ^Mozilla/4\\.0[678] no-gzip
BrowserMatch \\bMSIE !no-gzip !gzip-only-text/html
</IfModule>
<ifModule mod_headers.c>
Header unset ETag
</ifModule>
FileETag None
<IfModule prefork.c>
StartServers 44
MinSpareServers 22
MaxSpareServers 44
ServerLimit 300
MaxClients 200
MaxRequestsPerChild 0
</IfModule>
<IfModule worker.c>
StartServers 9
MaxClients 200
MinSpareThreads 110
MaxSpareThreads 330
ThreadsPerChild 110
MaxRequestsPerChild 0
</IfModule>
Options FollowSymLinks
#Deny hot linking images
[COLOR="red"]# RewriteCond %{HTTP_REFERER} !^$
# RewriteCond %{HTTP_REFERER} !^http://xyz.com/.*$ [NC] [OR]
# RewriteCond %{HTTP_REFERER} !^http://www.xyz.com/.*$ [NC] [OR]
# RewriteRule .*\\.(gif|GIF|jpg|JPG|png|PNG|bmp|BMP|wav|mp3|wmv|avi|mpeg)$ - [F][/COLOR]
# RewriteCond %{HTTP_REFERER} !^http(s)?://([-a-z0-9]+\\.)?xyz.com/ [NC] [OR]
# RewriteCond %{HTTP_REFERER} !^http(s)?://(.+\\.)?xyz.com/.*$ [NC]
# RewriteCond %{HTTP_REFERER} !^$
# RewriteCond %{HTTP_REFERER} !google. [NC]
# RewriteCond %{HTTP_REFERER} !search?q=cache [NC]
# RewriteCond %{HTTP_REFERER} !msn. [NC]
# RewriteCond %{HTTP_REFERER} !yahoo. [NC]
# RewriteRule .*\\.(gif|GIF|jpg|JPG|png|PNG|bmp|BMP|wav|mp3|wmv|avi|mpeg)$ nolinking.jpe [NC,R]
# RewriteCond %{HTTP_REFERER} !^http://(.+\\.)?xyz\\.co\\.uk/ [NC] [OR]
# RewriteCond %{HTTP_REFERER} !^http://(www\\.)?xyz\\.co\\.uk/.*$ [NC] [OR]
# RewriteCond %{HTTP_REFERER} !^$
# RewriteRule .*\\.(gif|GIF|jpg|JPG|png|PNG|bmp|BMP|wav|mp3|wmv|avi|mpeg)$ nolinking.png
# Deny access by user agents
RewriteCond %{HTTP_USER_AGENT} ^BlackWidow [OR]
RewriteCond %{HTTP_USER_AGENT} ^Bot\\ mailto:craftbot@yahoo.com [OR]
RewriteCond %{HTTP_USER_AGENT} ^ChinaClaw [OR]
RewriteCond %{HTTP_USER_AGENT} ^Custo [OR]
RewriteCond %{HTTP_USER_AGENT} ^DISCo [OR]
RewriteCond %{HTTP_USER_AGENT} ^Download\\ Demon [OR]
RewriteCond %{HTTP_USER_AGENT} ^eCatch [OR]
RewriteCond %{HTTP_USER_AGENT} ^EirGrabber [OR]
RewriteCond %{HTTP_USER_AGENT} ^EmailSiphon [OR]
RewriteCond %{HTTP_USER_AGENT} ^EmailWolf [OR]
RewriteCond %{HTTP_USER_AGENT} ^Express\\ WebPictures [OR]
RewriteCond %{HTTP_USER_AGENT} ^ExtractorPro [OR]
RewriteCond %{HTTP_USER_AGENT} ^EyeNetIE [OR]
RewriteCond %{HTTP_USER_AGENT} ^FlashGet [OR]
RewriteCond %{HTTP_USER_AGENT} ^GetRight [OR]
RewriteCond %{HTTP_USER_AGENT} ^GetWeb! [OR]
RewriteCond %{HTTP_USER_AGENT} ^Go!Zilla [OR]
RewriteCond %{HTTP_USER_AGENT} ^Go-Ahead-Got-It [OR]
RewriteCond %{HTTP_USER_AGENT} ^GrabNet [OR]
RewriteCond %{HTTP_USER_AGENT} ^Grafula [OR]
RewriteCond %{HTTP_USER_AGENT} ^HMView [OR]
RewriteCond %{HTTP_USER_AGENT} HTTrack [NC,OR]
RewriteCond %{HTTP_USER_AGENT} ^Image\\ Stripper [OR]
RewriteCond %{HTTP_USER_AGENT} ^Image\\ Sucker [OR]
RewriteCond %{HTTP_USER_AGENT} Indy\\ Library [NC,OR]
RewriteCond %{HTTP_USER_AGENT} ^InterGET [OR]
RewriteCond %{HTTP_USER_AGENT} ^Internet\\ Ninja [OR]
RewriteCond %{HTTP_USER_AGENT} ^JetCar [OR]
RewriteCond %{HTTP_USER_AGENT} ^JOC\\ Web\\ Spider [OR]
RewriteCond %{HTTP_USER_AGENT} ^larbin [OR]
RewriteCond %{HTTP_USER_AGENT} ^LeechFTP [OR]
RewriteCond %{HTTP_USER_AGENT} ^Mass\\ Downloader [OR]
RewriteCond %{HTTP_USER_AGENT} ^MIDown\\ tool [OR]
RewriteCond %{HTTP_USER_AGENT} ^Mister\\ PiX [OR]
RewriteCond %{HTTP_USER_AGENT} ^Navroad [OR]
RewriteCond %{HTTP_USER_AGENT} ^NearSite [OR]
RewriteCond %{HTTP_USER_AGENT} ^NetAnts [OR]
RewriteCond %{HTTP_USER_AGENT} ^NetSpider [OR]
RewriteCond %{HTTP_USER_AGENT} ^Net\\ Vampire [OR]
RewriteCond %{HTTP_USER_AGENT} ^NetZIP [OR]
RewriteCond %{HTTP_USER_AGENT} ^Octopus [OR]
RewriteCond %{HTTP_USER_AGENT} ^Offline\\ Explorer [OR]
RewriteCond %{HTTP_USER_AGENT} ^Offline\\ Navigator [OR]
RewriteCond %{HTTP_USER_AGENT} ^PageGrabber [OR]
RewriteCond %{HTTP_USER_AGENT} ^Papa\\ Foto [OR]
RewriteCond %{HTTP_USER_AGENT} ^pavuk [OR]
RewriteCond %{HTTP_USER_AGENT} ^pcBrowser [OR]
RewriteCond %{HTTP_USER_AGENT} ^RealDownload [OR]
RewriteCond %{HTTP_USER_AGENT} ^ReGet [OR]
RewriteCond %{HTTP_USER_AGENT} ^SiteSnagger [OR]
RewriteCond %{HTTP_USER_AGENT} ^SmartDownload [OR]
RewriteCond %{HTTP_USER_AGENT} ^SuperBot [OR]
RewriteCond %{HTTP_USER_AGENT} ^SuperHTTP [OR]
RewriteCond %{HTTP_USER_AGENT} ^Surfbot [OR]
RewriteCond %{HTTP_USER_AGENT} ^tAkeOut [OR]
RewriteCond %{HTTP_USER_AGENT} ^Teleport\\ Pro [OR]
RewriteCond %{HTTP_USER_AGENT} ^VoidEYE [OR]
RewriteCond %{HTTP_USER_AGENT} ^Web\\ Image\\ Collector [OR]
RewriteCond %{HTTP_USER_AGENT} ^Web\\ Sucker [OR]
RewriteCond %{HTTP_USER_AGENT} ^WebAuto [OR]
RewriteCond %{HTTP_USER_AGENT} ^WebCopier [OR]
RewriteCond %{HTTP_USER_AGENT} ^WebFetch [OR]
RewriteCond %{HTTP_USER_AGENT} ^WebGo\\ IS [OR]
RewriteCond %{HTTP_USER_AGENT} ^WebLeacher [OR]
RewriteCond %{HTTP_USER_AGENT} ^WebReaper [OR]
RewriteCond %{HTTP_USER_AGENT} ^WebSauger [OR]
RewriteCond %{HTTP_USER_AGENT} ^Website\\ eXtractor [OR]
RewriteCond %{HTTP_USER_AGENT} ^Website\\ Quester [OR]
RewriteCond %{HTTP_USER_AGENT} ^WebStripper [OR]
RewriteCond %{HTTP_USER_AGENT} ^WebWhacker [OR]
RewriteCond %{HTTP_USER_AGENT} ^WebZIP [OR]
RewriteCond %{HTTP_USER_AGENT} ^Wget [OR]
RewriteCond %{HTTP_USER_AGENT} ^Widow [OR]
RewriteCond %{HTTP_USER_AGENT} ^WWWOFFLE [OR]
RewriteCond %{HTTP_USER_AGENT} ^Xaldon\\ WebSpider [OR]
RewriteCond %{HTTP_USER_AGENT} ^Zeus
RewriteRule ^.* - [F]
# NameProtect peddles their “online brand monitoring” to unsuspecting and gullible companies
# looking for people to sue. Despite the claims on their robot information page, they do not
# respect robots.txt; in fact, they spoof their User-Agent in multiple ways to avoid detection.
# I have banned them by User-Agent and IP address.
RewriteCond %{REMOTE_ADDR} ^12\\.148\\.196\\.(12[8-9]¦1[3-9][0-9]¦2[0-4][0-9]¦25[0-5])$ [OR]
RewriteCond %{REMOTE_ADDR} ^12\\.148\\.209\\.(19[2-9]¦2[0-4][0-9]¦25[0-5])$ [OR]
RewriteCond %{HTTP_USER_AGENT} NPBot[NC]
RewriteRule .* - [F,L]