Administration
  Home arrow Administration arrow Page 8 - Getting More Out Of Apache (Part 2)
Dev Shed Forums 
Administration  
Apache  
BrainDump  
DHTML  
Flash  
Java  
JavaScript  
Multimedia  
MySQL  
Oracle  
Perl  
PHP  
Practices  
Python  
Reviews  
Security  
Style-Sheets  
Web Services  
XML  
Zend  
Zope  
Forums Sitemap 
IBM® developerWorks 
Dedicated Servers 
E-Commerce Hosting 
Linux Web Hosting 
Managed Hosting 
Small Business Hosting 
Download TestComplete 
VPS Hosting 
Weekly Newsletter

 
Developer Updates  
Free Website Content 
 RSS  Articles
 RSS  Forums
 RSS  All Feeds
Write For Us Get Paid 
Request Media Kit
Contact Us 
Site Map 
Privacy Policy 
Support 
 USERNAME
 
 PASSWORD
 
 
  >>> SIGN UP!  
  Lost Password? 
ADMINISTRATION

Getting More Out Of Apache (Part 2)
By: icarus, (c) Melonfire
  • Search For More Articles!
  • Disclaimer
  • Author Terms
  • Rating: 5 stars5 stars5 stars5 stars5 stars / 1
    2001-01-23

    Table of Contents:
  • Getting More Out Of Apache (Part 2)
  • Eyes Only
  • Identity Check
  • Grouping Things Together
  • Timmmmmmbbbbberrrr!
  • When Things Go Wrong
  • Just Rewrite It!
  • Putting It Into Practice

  • Rate this Article: Poor Best 
      ADD THIS ARTICLE TO:
      Del.ici.ous Digg
      Blink Simpy
      Google Spurl
      Y! MyWeb Furl
    Email Me Similar Content When Posted
    Add Developer Shed Article Feed To Your Site
    Email Article To Friend
    Print Version Of Article
    PDF Version Of Article
     
     
     
    ADVERTISEMENT

    Route your faxes to your email inbox. Private, secure fax numbers available from CallWave. Choose your fax number.

    Getting More Out Of Apache (Part 2) - Putting It Into Practice
    (Page 8 of 8 )

    One of the simplest applications of the rewriting engine is also one of itsmost valuable - the ability to prevent Internet users from using imagesfrom your site on theirs. By carefully using the rewriting rules incombination with server variables, you can set things up so that other Websites attempting to link to images on your site will not be granted access.

    Here are the lines you need to add to your configuration file:

    RewriteEngine On RewriteCond %{HTTP_REFERER} !^$ RewriteRule .*\.jpg$ - [F]
    The first directive is obvious - it turns the rewriting engine on. Once theengine is active, HTTP requests are scanned and matched against rules inthe file.

    The rules - there may be more than one, and they are interpreted in theorder in which they appear - are specified via regular expressions, as inthe example above. The first parameter following the RewriteRuledirective is a pattern, while the second is the substitution pattern; youcan also add special flags as a third parameter to invoke specificbehaviour.

    The rule above matches HTTP requests for images - files with the .jpgextension. Typically, you would replace these URLs with another string;however, I've used a hyphen to indicate that no substitution is totake place. Instead, I've used the [F] flag to have the server return a"403 Forbidden" result to the requestingclient.

    By itself, this is not enough - if you left it the way it was, everyrequest for an image would be denied. It's therefore necessary to add acondition which checks whether the request is from another server or not.This can be done by checking the value of the HTTP_REFERER variable, whichwill usually not be empty if the request is coming from another server. TheRewriteCond directive above checks the value of this variable, andactivates the rule only when the HTTP_REFERER variable is not empty.

    Another interesting application is using the rewriting engine to point yourWeb server's document root to a different physical location on yourserver's hard drive. For example, if you wanted all requests to the serverto be served from the folder

    /this/servers/new/root
    rather than

    /
    you could use this simple rule:

    RewriteEngine on RewriteRule ^/$ /this/servers/new/root/ [R]
    The [R] flag is used to indicate redirection.

    This are just two simple examples which demonstrate the power of URLrewriting - it gets more complex as you get deeper into it. If you'rereally interested in find out what else you can do with the URL rewritingengine, take a look at Ralf Engelschall's Web site athttp://www.engelschall.com/ , and at the Apache manual athttp://www.apache.org/docs/mod/mod_rewrite.html

    And that's about it from me for this week. See you soon!
    DISCLAIMER: The content provided in this article is not warranted or guaranteed by Developer Shed, Inc. The content provided is intended for entertainment and/or educational purposes in order to introduce to the reader key ideas, concepts, and/or product reviews. As such it is incumbent upon the reader to employ real-world tactics for security and implementation of best practices. We are not liable for any negative consequences that may result from implementing any information covered in our articles or tutorials. If this is a hardware review, it is not recommended to open and/or modify your hardware.

     

       

    ADMINISTRATION ARTICLES

    - Configuring Load-Balanced Clusters
    - Load-Balanced Clusters
    - UNIX Time Format Demystified
    - Making Changes in the CVS
    - Building Your First CVS Repository
    - CVS Quickstart Guide
    - Authorizing Users in Samba
    - Handling User Accounts in Samba
    - Authentication in Samba
    - Accounts, Authentication, and Authorization
    - Advanced Concepts on Dealing with Files and ...
    - Dealing with Files and Filesystems
    - More Hacks for the User Environment in BSD
    - Personalizing the User Environment in BSD
    - Customizing the User Environment in BSD

     
    Accelerating Trading Partner Performance
     
    Competing on Analytics
     
    Cost Effective Scaling with Virtualization and Coyote Point Systems
     
    Five Checkpoints to Implementing IP Telephony
     
    Hosted Email Security: Staying Ahead of New Threats
     




    © 2003-2008 by Developer Shed. All rights reserved. DS Cluster 3 hosted by Hostway