Web Development
  Home arrow Web Development arrow Module mod rewrite Tutorial (Part 1)
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 1)
By: Developer Shed
  • Search For More Articles!
  • Disclaimer
  • Author Terms
  • Rating: 4 stars4 stars4 stars4 stars4 stars / 10
    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 1
    By Dirk Brockhausen

    You may have encountered the name "mod_rewrite" before when surfing the web. For all of our readers who are not intimately familiar with this nifty Apache Web
    Server module - and, of course, for those who don't know it all - we are presenting this small introductory tutorial as a multipart serial.

    Module mod_rewrite is a package of program routines which can be added to the Apache Web Server. (Note that it will not run under other web servers!)

    Its primary function is the manipulation of URLs. The module is very versatile as we are going to illustrate here with a number of real world examples.

    However, be very careful and meticulous when working with it! Some mistakes you might be liable to make could generate a logical loop, causing a never-ceasing
    100% CPU load.

    To steer clear from this, we will start off with some very simple examples.


    Before we can get going, however, you will have to check whether the module is installed on your web server at all.

    There are several ways to go about this:

    1. Ask your system administrator - provided he or she knows. They really should, but unfortunately some plain do not ...
    Take care, though: if you are sharing your host server with hundreds of other domains, your inquiry might rouse some sleeping dogs, as usage of mod_rewrite will always entail some increased CPU load.

    2. Check your Apache configuration file if you can access it. One possible standard path might be: /etc/httpd/httpd.conf However, your mileage may obviously vary.

    3. Check it out with one of the following examples. If it works fine, mod_rewrite is indeed installed on your system. If it isn't, you will get the following message when calling any web page of your choice: "Internal Server Error"

    Also, you will see this entry in file "error.log": "Invalid command 'RewriteEngine', perhaps mis-spelled or defined by a module not included in the server configuration."

    If your site generates heavy traffic, this method is not recommended, as every visitor will receive this very same error message during your test.


    So now let's dig into our first practical example!

    We will assume that you will be using mod_rewrite only for your own web site, i.e. not as a generalized cross server setup.

    To effect this, some entries in file .htaccess are required.

    The .htaccess File
    For this technique to work, you will need to upload a file named ".htaccess" (please note the period/dot at the beginning of the file name!) to your server
    directory. This can be done via telnet or ftp. (Warning! .htaccess should only be uploaded in "ASCII mode", i.e. not in binary mode!)

    If you already have a ".htaccess" file, for example one with the following entries:

    Options Includes +ExecCGI AddType text/x-server-parsed-html .html

    simply add our code sample to it.

    IMPORTANT!

    ADJUSTMENTS IN FILE ".htaccess": please edit in ASCII or plain text editor like Notepad etc.

    The first two entries will start the module:

    RewriteEngine on
    Options +FollowSymlinks

    Tip: Entry "RewriteEngine off" will override all subsequent commands. This is a very useful feature: instead of having to comment out all subsequent lines, all you need to do is set an "off".

    If your system administrator does not allow for implementation of "Options +FollowSymlinks", you will not be able to restrict usage of mod_rewrite to
    your directories but will instead have to apply it server wide.

    The next required entry is this:

    RewriteBase /

    "/" stands for the base URL. Should you have another one, you will want to include it. However, "/" is normally the entry for "http://www.YourDomain.com".

    And now to the entries proper!

    Let us assume that you want to block unauthorized access to your file .htaccess. On some servers you can easily read this file simply by entering a URL of the following format in your browser's address field: http://www.domain.com/.htaccess - a serious
    security gap, as your .htaccess file's contents may reveal more about your site's setup to the educated eye than you may want others to know.


    To block this access, enter the following:

    RewriteRule ^\.htaccess$ - [F]

    This rule translates to:

    If someone tries to access file .htaccess, system shall generate error code "HTTP response of 403".

    The file name ^\.htaccess$ is contained in a regular expression, to wit:

    ^ Start of line anchor
    $ End of line anchor
    \. In regular expressions the dot "." denotes a
    meta character and must be protected by a backslash (\) if you want an actual dot (period) instead.

    The file name must be located exactly between start and end of line anchor. This will ensure that only this specific file name and no other will generate the error code.

    [F] : special flag "forbidden".

    In this example, the complete ".htaccess" file will now consist of these lines:

    RewriteEngine on
    Options +FollowSymlinks
    RewriteBase /
    RewriteRule ^\.htaccess$ - [F]

    If we add our code to a pre-existing ".htaccess" file, we might, for example, get the following entries:

    Options Includes +ExecCGI
    AddType text/x-server-parsed-html .html
    RewriteEngine on
    Options +FollowSymlinks
    RewriteBase /
    RewriteRule ^\.htaccess$ - [F]


    This introduction covers the basics required to operate with mod_rewrite.

    In the second part of this tutorial we will explain the use of conditions in configuring the module.

    You may check up general documentation here:
    --------------------------------------------
    Module mod_rewrite URL Rewriting Engine:
    http://www.apache.org/docs/mod/mod_rewrite.html

    A Users Guide to URL Rewriting with the
    Apache Webserver:
    http://www.engelschall.com/pw/apache/rewriteguide/

    Continue with this tutorial >>>

     


    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!


    NEW! Integrating XML into Your Enterprise Using Data Federation

    XML has become a common way of storing business data as flat files and many data server vendors including IBM have provided ways to store this data within relational database systems. Increasingly collections of XML files are accessed like databases using an xQuery and other XML standard mechanisms. Businesses find the need to combine the traditional tabular structured data with XML formatted data. In this webcast, you’ll learn about IBM’s WebSphere Federation Server technology, which provides users with the ability to integrate these two data formats.
    FREE! Go There Now!


    NEW! Download IBM WebSphere Portal V6.1 beta code

    Download the IBM WebSphere Portal V6.1 beta code and learn more about the rich features and enhancements in IBM WebSphere Portal V6.1. WebSphere Portal provides a composite application or business mashup framework and the advanced tooling needed to build flexible, SOA-based solutions, and scalability to meet the needs of any size organization.
    FREE! Go There Now!


    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! Using Rational Business Developer to enhance your developer productivity

    Join this Rational Talks to You teleconference, to hear how Enterprise Generation Language (EGL) eliminates the need for tedious and error-prone low level coding, so developers can focus on business requirements. EGL extends the Rational software development platform with a simplified programming language that enables developers who have little or no experience with Java, Web technologies or Service Oriented Architecture, to create enterprise-class applications and services quickly and easily. It also allows developers who may have little or no mainframe programming experience to quickly create traditional mainframe components.
    FREE! Go There Now!


    NEW! Develop Systems Software Assets with IBM Rational Asset Manager

    Join us for this on demand webcast to learn about developing complex systems more quickly and efficiently. We'll cover market drivers for developing, governing and reusing systems software assets and how you can develop system software assets with Rational Asset Manager.
    FREE! Go There Now!


    NEW! Build Web services with transport-level security using Rational Application Developer V7, Part 1: Build Web services and Web services clients

    Build secure Web services with transport-level security using IBM Rational Application Developer V7 and IBM WebSphere Application Server V6.1. Follow this three-part series for step-by-step instructions about how to develop Web services and clients, configure HTTP basic authentication, and configure HTTP over SSL (HTTPS). This first part of the series walks you through building a Web service for a simple calculator application. You generate and test two different types of Web services clients: a Java Platform, Enterprise Edition (Java EE) client and a stand-alone Java client. You also handle user-defined exceptions in Web services.
    FREE! Go There Now!


    Build Forge Express demo: Enabling software delivery excellence for small and midsized businesses

    This demonstration gives you an overview of IBM® Rational® Build Forge Express Edition, a global offering that provides a framework to automate and execute software processes. Rational Build Forge provides a software assembly line that can support all of your tools, technologies, and platforms so you can achieve a repeatable, reliable, and traceable build and release process.
    FREE! Go There Now!


    NEW! IBM Rational AppScan Standard Edition V7.7

    Secure your Web applications with IBM Rational AppScan Standard Edition V7.7, previously known as Watchfire AppScan. This Web application security testing tool automates vulnerability assessments and scans and tests for common Web application vulnerabilities. Visit IBM developerWorks to download a free trial of IBM Rational AppScan Standard Edition V7.7.
    FREE! Go There Now!


    NEW! Evaluate IBM Lotus Sametime Standard V8.0

    Visit IBM developerWorks to download a free trial of the latest release of IBM Lotus Sametime Standard V8.0. Lotus Sametime Standard V8.0 is a platform for unified communications and collaboration that combines security features with an extensible, open solution including integrated Voice over IP, geographic location awareness, mobile clients, and a robust Business Partner community offering telephony and video integration.
    FREE! Go There Now!


    NEW! IBM Enterprise Modernization Sandbox for System z

    IBM Enterprise Modernization solutions help organizations evolve core IT systems towards modern architectures and technologies—reducing the burden of maintenance and freeing up resources to develop new business requirements and capabilities. With the IBM Enterprise Modernization Sandbox for System z you can evaluate IBM Enterprise Modernization solutions focused on five key areas: Assets, Architectures, Skills, Processes and Infrastructures, and Investment. Each solution is based upon real customer experiences and offers a proven path to get you started with your modernization projects.
    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 5 Hosted by Hostway
    Stay green...Green IT