Web Development
  Home arrow Web Development arrow Module mod rewrite Tutorial (Part 4)
Affiliate Promotion  
Blog Help  
Domain Name Tips  
How To  
Newsletter Marketing  
Online Business Help  
Search Engine Tricks  
Web Development  
Web Hosting  
Website Advertising  
Website Content  
Website Marketing  
 Webmaster Tools
 
Base64 Encoding 
Browser Settings 
CSS Coder 
CSS Navigation Menu 
Datetime Converter 
DHTML Tooltip 
Dig Utility 
DNS Utility 
Dropdown Menu 
Fetch Content 
Fetch Header 
Floating Layer 
htaccess Generator 
HTML to PHP 
HTML Encoder 
HTML Entities 
IP Convert 
Meta Tags 
Password Encryption
 
Password Strength
 
Pattern Extractor 
Ping Utility 
Pop-Up Window 
Regex Extractor 
Regex Match 
Scrollbar Color 
Source Viewer 
Syntax Highlighting 
URL Encoding 
Web Safe Colors 
Whois
 
Forums Sitemap 
Mobile Linux 
APP Generation ROI 
IBM® developerWorks 
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? 
WEB DEVELOPMENT

Module mod rewrite Tutorial (Part 4)
By: Developer Shed
  • Search For More Articles!
  • Disclaimer
  • Author Terms
  • Rating: 4 stars4 stars4 stars4 stars4 stars / 9
    2003-08-09

    Table of Contents:

    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


    The Apache server power commander part 4
    By Dirk Brockhausen

    In this final part of our tutorial we will take a look at those special directives we haven't covered yet.

    These directives cannot be defined on directory level.

    This means that you will have to be able to edit the Apache webserver's configuration file (httpd.conf). These permissions will usually only be assigned to users "root" or "admin".

    If you wish to log all operations effected by mod_rewrite you can activate logging with the
    following entries:

    RewriteLog /usr/local/apache/logs/mod_rewrite_log
    RewriteLogLevel 1

    These entries are not written into the file ".htaccess" but in "Section 2: 'Main' server
    configuration" of file "httpd.conf".

    All mod_rewrite manipulations will be logged in this file. The log file can have any name you prefer. It can be referenced as an absolute path or relative to ServerRoot.

    If you wish to maintain separate log files for individual virtual hosts, you will have to place the pertinent entries in "Section 3: Virtual Hosts",
    e.g.:

    <VirtualHost 192.168.1.1>
    ServerAdmin webmaster@yourdomain.com
    DocumentRoot /usr/www/htdocs/yourdomain
    ServerName yourdomain.com
    RewriteLog /usr/apache/logs/yourdomain_mod_rewrite_log
    RewriteLogLevel 1
    </VirtualHost>

    (Note: If your email reader or browser wraps these lines take care to enter them unwrapped in your file!)

    The RewriteLogLevel can be defined within a range of 1 to 8. Normally, 1 will do fine. Higher levels are only required for debugging purposes.

    Another directive which is very handy for cloaking purposes are the so-called Rewriting Maps. These are files consisting of key/value pairs, e.g. in the simple format of an ordinary text file:

    cde2c920.infoseek.com spider
    205.226.201.32 spider
    cde2c923.infoseek.com spider
    205.226.201.35 spider
    cde2c981.infoseek.com spider
    205.226.201.129 spider
    cde2cb23.infoseek.com spider
    205.226.203.35 spider

    These keys are, as you can see, hostnames or IPs. In this simplistic example the value is always the same, namely "spider".

    This directive is entered either in the server section 2 or in the virtual host section 3 in file
    "httpd.conf":

    RewriteMap botBase txt:/www/yourdomain/spiderspy.txt

    The Rewriting Map will then be available across your server.

    The other directives are entered in file ".htaccess":

    RewriteCond ${botBase:%{REMOTE_HOST}} =spider [OR]
    RewriteCond ${botBase:%{REMOTE_ADDR}} =spider
    RewriteRule ^(.*)\.htm$ $1.htm [L]
    RewriteRule ^.*\.htm$ index.html [L]

    The conditions will make the system check whether the required access is generated by a spider. To this effect a lookup of file "spiderspy.txt" is triggered.

    If the key is found, the value "spider" is returned and the condition is rendered as true.

    Next, the first RewriteRule will be executed. This one determines that the called for ".htm" page will be fed to the spider. The variable $1 is equal to the part in
    parentheses of "^(.*)\.htm$", i.e. the file name will remain the same.

    If the URL is called by a normal human visitor, rule 2 applies: the user will be redirected to page "index.html".

    As the ".htm" pages will only be read by spiders, they can be optimized accordingly for the search engines.

    You may also use a file in dbm format instead of an ordinary text file. The binary data base format helps accelerate the lookup which is particularly important if you are operating from very large spider lists.

    This example given above offers a simple cloaking functionality. All ordinary visitors will always be redirected to the site's "index.html" page and there is no access logging beyond the mod_rewrite logs.

    However, it does go to show how you can effectively replace several lines of Perl code with just a few lines of mod_rewrite.

    Our last example will illustrate this in some greater detail.

    The objective is to present site visitors with your
    "Picture of the Day". Visitors will click a link, e.g.:
    < http://www.yourdomain.com/pic.html >
    which will display a different picture every day.

    We will work from these server variables:

    TIME_MON
    TIME_DAY

    In file ".htaccess" we will enter the following single code line:

    RewriteRule ^pic.html$ pic-%{TIME_MON}-%{TIME_DAY}.html

    (Note: If your email reader or browser wraps this line take care to enter it unwrapped in your file!)

    The URL called for will be rewritten, e.g. to:

    pic-08-28.html
    pic-08-29.html
    pic-08-30.html
    etc.

    So all you have to do is upload the pertinent files once, after which you won't need to tend to their daily assignation anymore.

    Obviously the time variables can also be used for other periodicities.

    With this final example our mod_rewrite tutorial has come to its end.

    Of course, we have not tackled each and every directive, variable, etc. here.

    Rather, we suggest you view this tutorial as a general introduction intended to help you as a start off point towards a more in-depth study of the mod_rewrite module, enabling you to customize it according to your specific requirements.


    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.

    More Web Development Articles
    More By Developer Shed

     

    IBM® developerWorks developerWorks - FREE Tools!


    Role of Integrated Requirements Management in Software Delivery

    As organizations integrate software into every aspect of business, they are constantly pressured to deliver faster, better, and cheaper results. Unfortunately, a “dis-integrated” software delivery approach reduces returns while increasing costs. This IBM Rational White Paper shows how Integrated Requirements Management aligns organizations around maximizing value and keeping pace with change.
    FREE! Go There Now!


    NEW! Run your first CICS application on a PC using TXSeries for Windows

    Learn the basics of the IBM Customer Information Control System (CICS). With a hands-on exercise, learn how to get your first CICS application up and running on your desktop using TXSeries V6.1 for Windows. The tutorial shows you how to download and install a free trial version of TXSeries V6.1.
    FREE! Go There Now!


    NEW! Calling all CC Power Users – and those that would like to be!

    Join this Rational Talks to You teleconference, featuring Paul Boustany and Mark Krasovich, to speak to the experts about becoming a Rational ClearCase power user. Get a chance to ask your questions and learn tips and tricks for using Rational ClearCase in Agile development
    FREE! Go There Now!


    NEW! Rational Talks to You: Grady Booch on Architecture

    Join this Rational Talks to You teleconference on November 29 at 1:00 pm ET to participate in an interactive discusssion with Grady Booch around architecture and reuse. Get your questions answered!
    FREE! Go There Now!


    Be the first to hear about i5/OS V6R1!

    Hold your calendar on January 30, 2008 for this free webcast on the new i5/OS. Rational's Enterprise Modernization products will be discussed at this webcast as they help to drive the application development environment for this new System i OS. <br />And learn how i5/OS will take you to the next step of efficient, resilient business processing. You will hear about the new i5/OS capabilities as it will be the most significant i5/OS release in years. If you cannot join the webcast on 1/30/08 you can still use this link to listen to the replay.<br />
    FREE! Go There Now!


    NEW! Improve your build process with IBM Rational Build Forge, Part 1: Create a continuous build and integration environment

    Learn how to implement a build management system that uses and extends your existing automation technologies. This tutorial shows, step-by-step, how to install and configure IBM Rational Build Forge to manage builds for Jakarta Tomcat from source code.
    FREE! Go There Now!


    NEW! Driving Business Success with Rational Process Library

    Join this webcast, to learn how the Rational Process Library can help with compliance issues, drive process improvement, and assist in service-oriented architecture (SOA) or Agile development. We will take a peek into the Rational Process Library with content around software and systems engineering (including RUP), operations and systems management, program and portfolio management, and asset and SOA governance.
    FREE! Go There Now!


    NEW! Webcast: Eclipse: Empowering the universal platform

    The Eclipse community is constantly working to extend Eclipse's functionality. In this webcast, learn about some of the most important and feature-rich projects under development. From multi-language support to plug-in development, tune in to see what Eclipse is capable of now.
    FREE! Go There Now!


    NEW! Download IBM Data Studio V1.1

    Visit IBM developerWorks to download the latest trial version of IBM Data Studio V1.1 at no cost. IBM Data Studio is a comprehensive data management solution that helps you effectively design, develop, deploy and manage your data, databases, and database applications throughout the data management life cycle utilizing a consistent and integrated user interface. Unlike other client-side data management solutions that focus on only one aspect of the application lifecycle or database administration, Data Studio complements the Rational Software Delivery platform, providing unparalleled flexibility for a heterogeneous data server environment across platforms.
    FREE! Go There Now!


    NEW! Try the IBM SOA Sandbox for Connectivity

    Visit IBM developerWorks to try the IBM SOA Sandbox for connectivity. The SOA Sandbox for connectivity provides a trial environment with the tooling and components to help you explore how to effectively connect your infrastructure and integrate all of the people, processes and information in your company. Use the hosted sandbox to explore SOA techniques that streamline connecting existing IT assets together, as well as learn how to connect them to new business logic.
    FREE! Go There Now!



    All FREE IBM® developerWorks Tools!

       

    WEB DEVELOPMENT ARTICLES

    - Make Your WordPress Website Look Professional
    - How to Create a Mobile Web Site
    - Meta Tags: Still Useful?
    - Build a Completely Free Site
    - Is Your Site Secure?
    - What`s So Special About Your Site?
    - Add Games to Your Site
    - Should You Offer E-mail?
    - The Trouble with CAPTCHA
    - Add Images Responsibly
    - Is There a Science to Site Design?
    - Shortcuts for Page Design
    - Rebranding a Community
    - Firebug Firefox Extension Review
    - Is a CMS or Custom Code Better for Your Web ...

     
    Create the Optimal Architecture for your Critical Applications
    Warburton's the largest independently owned bakery in the UK faced a number of d....

     
    Five Best Practices for Deploying a Successful Service-Oriented Architecture
    This white paper describes the benefits you can expect with SOA, and how IBM can....

     
    Gartner Magic Quadrant for Application Delivery Controllers
    Gartner summarizes its view on Application Delivery Controllers, evaluates stren....

     
    Knowledge is Power
    What you don't know can hurt you, and is likely costing you money and increasing....

     
    Rationalizing the Multi-Tool Environment
    The rationalized multi-tool approach is flexible, scalable and cost effective. I....

     




    © 2003-2009 by Developer Shed. All rights reserved. DS Cluster 3 Hosted by Hostway
    Stay green...Green IT