• Login
  • Register
  • Account
  • About 'corePHP'
  • Portfolio
  • SiteMap

Joomla! Development, Professional Joomla! Templates, Components, Extensions and Plugins — 'corePHP

Professional website development and design services

  • Home
  • Joomla! Products
    • Components
      • Community ACL
      • Droomla
      • jomCalendar
      • jomLike
      • JPhoto
      • Mortgage Calculators
      • WordPress
    • Plugins
      • Amazon Pack
      • Automated CSS3 Generator
      • Chimp Your Joomla!
      • JAutosearch
      • jomCDN
      • jomDefender
      • VirtueMart Age Restriction Plugin
    • jomSocial Add-ons
      • jomGive
    • Dreamweaver
      • Template Basics
    • JPhoto Add-ons
      • JPhoto Slideshow
    • cACL Add-ons
      • DOCman Plugin
    • CB Plugins
      • DOCman Downloads
    • Modules
      • YouTube Module
  • Templates
    • Joomla Themes
    • WordPress Themes
    • Drupal Themes
  • Services
    • Joomla! Services
      • Joomla! Install and Upgrading Services
      • Joomla! Website Design/Maintenance
      • Joomla! Custom Development
      • Joomla! Component Development
    • Template Services
      • Joomla! Template Conversion
      • Joomla! Template Design
      • PSD Template Design
    • Print Service
      • Print Design
  • Resources
    • Affiliate Club
    • Search Engine Submissions
    • 'corePHP' Partners
  • Blog
  • Support
    • Submit Ticket
    • Community Forums
  • Contact Us

Search the Blog

  • Categories

    • 'corePHP'
    • 'corePHP' Products
    • Accessibility
    • Dreamweaver
    • Expos
    • Flash
    • Graphics
    • Javascript
    • Joomla
    • Marketing
    • Mobile
    • Operating System
    • Other
    • PHP
    • Print
    • Public News Articles
    • Recommended Software
    • security
    • Templates
    • Tools
    • Uncategorized
    • XHTML+CSS
  • Pages

    • Chicago ’09
    • Denver Expo / Fun
  • Archives

    • February 2012
    • January 2012
    • December 2011
    • November 2011
    • October 2011
    • September 2011
    • August 2011
    • July 2011
    • June 2011
    • May 2011
    • April 2011
    • March 2011
    • February 2011
    • January 2011
    • December 2010
    • November 2010
    • October 2010
    • September 2010
    • August 2010
    • July 2010
    • June 2010
    • May 2010
    • April 2010
    • March 2010
    • February 2010
    • January 2010
    • December 2009
    • November 2009
    • October 2009
    • September 2009
    • August 2009
    • July 2009
    • June 2009
    • May 2009
    • April 2009
    • March 2009
    • February 2009
    • January 2009
    • December 2008
    • November 2008
    • October 2008
    • May 2008
    • February 2008
    • January 2008
    • September 2007
    • April 2007
    • February 2007
    • December 2006
    • September 2006
    • August 2006
    • July 2006
    • June 2006
    • May 2006

Tag Cloud

'corePHP'  Android  app  Battle Creek  bugs  Christmas  CMS Expo  community  Community Acl  css  denver  discount  fix  holidays  html  ie  ie6  iOS  jomCDN  jomMobile  jomsocial  Joomla  Joomla! 1.5  Joomla! 1.6  Joomla Chicago  joomla extensions  joomla products  JPhoto  mobile  new products  new release  PHP  plugins  products  sale  security  small business  snippets  Steven Pignataro  success  template  tips  WordPress  WordPress MU  youtube

'corePHP' Blog


Keep up to date on what's happening at 'corePHP'

« WordPress 2.7.1.1 for Joomla!
Quick WordPress Fix »

.htaccess Security

htaccess jungle

Here is most of our .htaccess file. This is what I like to call the forefront of our site. It works just like a firewall. We have been using our .htaccess for a few months now and we love the results. I know it can occasionally be hard to find the right command to do the job, so I’d like to show you all of the lines, not just the ones that are security related. If you are not using Joomla! you will have to strip about ten lines from this.

This is a great reference piece, and I strongly recommend the use of most of this file.

# Lets deny some users
# deny from xx.xxx.xxx.xxx

# Use Options
Options +FollowSymLinks

#  mod_rewrite in use
RewriteEngine On

#  Uncomment following line if your webserver’s URL
#  is not directly related to physical file paths.
#RewriteBase /

RewriteCond %{HTTP_HOST} ^corephp\.com
RewriteRule ^(.*)$ http://www.corephp.com/$1 [R=permanent,L]

#Redirect moved pages
Redirect 301 /old-link.html http://www.corephp.com/new-link.html

#Rewrites
RedirectMatch    ^/somedir(/)?$   http://www.corephp.com/index.php?option=com_somecomponent

ServerSignature Off
RewriteCond %{REQUEST_METHOD}  ^(HEAD|TRACE|DELETE|TRACK) [NC,OR]
RewriteCond %{THE_REQUEST}     ^.*(\\r|\\n|%0A|%0D).* [NC,OR]

RewriteCond %{HTTP_REFERER}    ^(.*)(<|>|’|%0A|%0D|%27|%3C|%3E|%00).* [NC,OR]
RewriteCond %{HTTP_COOKIE}     ^.*(<|>|’|%0A|%0D|%27|%3C|%3E|%00).* [NC,OR]
RewriteCond %{REQUEST_URI}     ^/(,|;|:|<|>|”>|”<|/|\\\.\.\\).{0,9999}.* [NC,OR]

RewriteCond %{HTTP_USER_AGENT} ^$ [OR]
RewriteCond %{HTTP_USER_AGENT} ^(java|curl|wget).* [NC,OR]
RewriteCond %{HTTP_USER_AGENT} ^.*(winhttp|HTTrack|clshttp|archiver|loader|email|harvest|extract|grab|miner).* [NC,OR]
RewriteCond %{HTTP_USER_AGENT} ^.*(libwww-perl|curl|wget|python|nikto|scan).* [NC,OR]
RewriteCond %{HTTP_USER_AGENT} ^.*(<|>|’|%0A|%0D|%27|%3C|%3E|%00).* [NC,OR]

RewriteCond %{QUERY_STRING}    ^.*(;|<|>|’|”|\)|%0A|%0D|%22|%27|%3C|%3E|%00).*(/\*|union|select|insert|cast|set|declare|drop|update|md5|benchmark).* [NC,OR]
RewriteCond %{QUERY_STRING}    ^.*(localhost|loopback|127\.0\.0\.1).* [NC,OR]
RewriteCond %{QUERY_STRING}    ^.*\.[A-Za-z0-9].* [NC,OR]
RewriteCond %{QUERY_STRING}    ^.*(<|>|’|%0A|%0D|%27|%3C|%3E|%00).* [NC]

########## Begin – Rewrite rules to block out some common exploits
## If you experience problems on your site block out the operations listed below
## This attempts to block the most common type of exploit `attempts` to Joomla!
## Block out any script trying to set a mosConfig value through the URL
RewriteCond %{QUERY_STRING} mosConfig_[a-zA-Z_]{1,21}(=|\%3D) [OR]
# Block out any script trying to base64_encode crap to send via URL
RewriteCond %{QUERY_STRING} base64_encode.*\(.*\) [OR]
# Block out any script that includes a <script> tag in URL
RewriteCond %{QUERY_STRING} (\<|%3C).*script.*(\>|%3E) [NC,OR]
# Block out any script trying to set a PHP GLOBALS variable via URL
RewriteCond %{QUERY_STRING} GLOBALS(=|\[|\%[0-9A-Z]{0,2}) [OR]
# Block out any script trying to modify a _REQUEST variable via URL
RewriteCond %{QUERY_STRING} _REQUEST(=|\[|\%[0-9A-Z]{0,2})
# Send all blocked request to homepage with 403 Forbidden error!
RewriteRule ^(.*)$ index.php [F,L]
########### End – Rewrite rules to block out some common exploits

########## Begin – Joomla! core SEF Section#
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_URI} !^/index.php
RewriteCond %{REQUEST_URI} (/|\.php|\.html|\.htm|\.feed|\.pdf|\.raw|/[^.]*)$  [NC]
RewriteRule (.*) index.php
RewriteRule .* – [E=HTTP_AUTHORIZATION:%{HTTP:Authorization},L]
########### End – Joomla! core SEF Section

########## Block bad 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} ^Widow [OR]
RewriteCond %{HTTP_USER_AGENT} ^WWWOFFLE [OR]
RewriteCond %{HTTP_USER_AGENT} ^Xaldon\ WebSpider [OR]
RewriteCond %{HTTP_USER_AGENT} ^Zeus
RewriteRule ^.* – [F,L]

Credit for part of this .htaccess file goes to Ronald van den Heetkamp. Sadly, his website is no longer available.
Image created by Wordle

Share this:
  • Digg
  • del.icio.us
  • Twitter
  • StumbleUpon
  • email
  • Facebook
  • Fark
  • LinkedIn
  • Technorati
  • Google Bookmarks
  • Reddit

Tags: htaccess, security

This entry was posted on Saturday, February 28th, 2009 at 2:00 pm by Rafael Corral and is filed under Tools. You can follow any responses to this entry through the RSS 2.0 feed. You can leave a response, or trackback from your own site.

8 Responses to “.htaccess Security”

  1. wmena says:
    March 2, 2009 at 2:48 pm

    On my hosting provider, one of the lines above fails:

    RewriteCond %{REQUEST_URI} ^/(,|;|:||”>|”<|/|\\\.\.\\).{0,9999}.* [NC,OR]

    Now, I did do a search and found that the quotes that you have above and what most others have when using this line are different: ” vs ”

    Still, I get an error 500 on my site whenever I un-comment that 1 line in my htaccess file… regardless of which quote I use.

  2. Rafael Corral says:
    March 2, 2009 at 4:09 pm

    wmena,
    I fixed those quotes, there was a problem with the single and double quotes throughout the post.
    Please try it again.

  3. Jim Longo says:
    January 12, 2010 at 10:35 am

    I still have a problem with that specific line, it gives me a 500 error

    RewriteCond %{REQUEST_URI} ^/(,|;|:||”>|”<|/|\\\.\.\\).{0,9999}.* [NC,OR]

  4. Rafael Corral says:
    January 12, 2010 at 11:15 am

    Have you looked into your server error logs to see what the error is?
    I am guessing it is a misconfiguration on your server as we use that on many sites and haven’t had a problem yet.

  5. Kieran says:
    February 18, 2010 at 9:17 am

    Hi Rafael,

    You stated:

    “If you are not using Joomla! you will have to strip about ten lines from this.”

    Could you be specific about these lines.
    Thank you

  6. Rafael Corral says:
    February 18, 2010 at 10:12 am

    Removing all of this should do it, more than 10 lines :)

    ########## Begin – Rewrite rules to block out some common exploits
    ## If you experience problems on your site block out the operations listed below
    ## This attempts to block the most common type of exploit `attempts` to Joomla!
    ## Block out any script trying to set a mosConfig value through the URL
    RewriteCond %{QUERY_STRING} mosConfig_[a-zA-Z_]{1,21}(=|\%3D) [OR]
    # Block out any script trying to base64_encode crap to send via URL
    RewriteCond %{QUERY_STRING} base64_encode.*\(.*\) [OR]
    # Block out any script that includes a tag in URL
    RewriteCond %{QUERY_STRING} (\|%3E) [NC,OR]
    # Block out any script trying to set a PHP GLOBALS variable via URL
    RewriteCond %{QUERY_STRING} GLOBALS(=|\[|\%[0-9A-Z]{0,2}) [OR]
    # Block out any script trying to modify a _REQUEST variable via URL
    RewriteCond %{QUERY_STRING} _REQUEST(=|\[|\%[0-9A-Z]{0,2})
    # Send all blocked request to homepage with 403 Forbidden error!
    RewriteRule ^(.*)$ index.php [F,L]
    ########### End – Rewrite rules to block out some common exploits

    ########## Begin – Joomla! core SEF Section#
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteCond %{REQUEST_URI} !^/index.php
    RewriteCond %{REQUEST_URI} (/|\.php|\.html|\.htm|\.feed|\.pdf|\.raw|/[^.]*)$ [NC]
    RewriteRule (.*) index.php
    RewriteRule .* – [E=HTTP_AUTHORIZATION:%{HTTP:Authorization},L]
    ########### End – Joomla! core SEF Section

  7. Peter says:
    March 26, 2010 at 2:42 am

    I also have to suncomment the following line to make it work. Otherwise I get a 500 error page.
    RewriteCond %{REQUEST_URI} ^/(,|;|:||”>|”<|/|\\\.\.\\).{0,9999}.* [NC,OR]
    After experimenting with a couple of different variations of the single signs I found that the error page disappears when I change the brackets from {} to ().
    I am not so familiar with the code details so my question is: Does the RewriteCond still make sense when I change these brackets or does it have a completely different meaning now and maybe lost its original intention?

  8. Rafael Corral says:
    March 28, 2010 at 3:22 pm

    {} are used for quantity and repetitions
    () are used for grouping.
    Therefore, yes your change probably broke what that rewrite was meant to do.

    For more information read here:
    http://www.regular-expressions.info/reference.html

Leave a Reply

Click here to cancel reply.

User Information

Message


'corePHP' Blog is proudly powered by WordPress. Joomla! extensions by 'corePHP'
Entries (RSS) and Comments (RSS).

  • Here is most of our .htaccess file. This is what I like to call the forefront of our site. It works just

'corePHP' at a Glance

  • About 'corePHP'
  • Portfolio
  • SiteMap

Joomla! Products

  • Joomla! Components
  • Joomla! Modules
  • Joomla! Plugins
  • Dreamweaver Snippets

Services

  • Joomla! Install and Upgrading Services
  • Joomla! Website Design/Maintenance
  • Joomla! Custom Development
  • Joomla! Component Development
  • Joomla! Template Conversion
  • Joomla! Template Design
  • PSD Template Design
  • Print Design

Resources

  • Search Engine Submissions
  • 'corePHP' Partners
  • Blog

Contact

  • Contact Us
  • Support Desk
  • Forums

Policy Statement

  • Terms of Service
  • Refund Policy
  • Cancel Subscription

Contact Us

(269) 979-5582
62 East Michigan Ave.
Suite 202
Battle Creek, MI 49017

Join Our Mailing List

Affiliate Club
Become an affiliate!

©2011 'corePHP' All Rights Reserved – Designed by 'corePHP'

  • Twitter
  • Plurk
  • Digg It
  • Facebook
  • LinkedIN
  • RSS