Computer articles :: Module mod_rewrite Tutorial (Part 1) :: Computer articles for websites
Google

Web Torroid

Free Sex and Sexuality Guide
Free Sex and Sexuality Guide
Free Web and Internet Directory
Free Web and Internet Directory
DNS Services
DNS Services
Office Humor Cartoon Poetry
Office Humor Cartoon Poetry
IT Support London
IT Support London
online casino gambling
online casino gambling

Mortgage Loans
Loans
MySpace Layouts
Internet Advertising
Credit Report
Advertise here
Affiliates
Reviews
Help Youth
Defeating Stigma
structured settlement news

Module mod_rewrite Tutorial (Part 1)

Next articles:

Module mod_rewrite Tutorial (Part 2) - In this tutorial's last instalment we started off with a discussion of the basics of Module mod_rewrite. In the example reviewed there we made...

Cloaking For Google - Don't cloak for Google - they don't like it! :-) However, if you must cloak for Google whatever the reason, take great care...

Module mod_rewrite Tutorial (Part 3) - In the two preceding parts of this tutorial we explained the basics of Rules and Conditions. We will now follow up with two examples to illustrate their use for somewhat more...

Module mod_rewrite Tutorial (Part 4) - 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...

Code Protection Under Cold Fusion - By default, Cold Fusion poweredn sites won't allow for .htaccess functionality which makes it difficult to...

The Apache Server Power Commander 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/

(to be continued ...)

Dirk Brockhausen is the co-founder and principal of fantomaster.com Ltd. (UK) and fantomaster.com GmbH (Belgium), a company specializing in webmasters software development, industrial-strength cloaking and search engine positioning services. He holds a doctorate in physics and has worked as an SAP consultant and software developer since 1994. He is also Technical Editor of fantomNews, a free newsletter focusing on search engine optimization, available at: < http://fantomaster.com/fantomnews-sub.html > You can contact him at mailto:fntecheditor@fantomaster.com (c) copyright 2000 by fantomaster.com

Link to this article, just copy and paste following code:

<a href=http://www.torroid.com/article1182.html>Module mod_rewrite Tutorial (Part 1)</a>

Article viewed 785 time(s). Read more:

1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | 44 | 45 | 46 | 47 | 48 | 49 | 50 | 51 | 52 | 53 | 54 | 55 | 56 | 57 | 58 | 59 | 60 | 61 | 62 | 63 | 64 | 65 | 66 | 67 | 68 | 69 | 70 | 71 | 72 | 73 | 74 | 75 | 76 | 77 | 78 | 79 | 80 | 81 | 82 | 83 | 84 | 85 | 86 | 87 | 88 | 89 | 90 | 91 | 92 | 93 | 94 | 95 | 96 | 97 | 98 | 99 | 100 | 101 | 102 | 103 | 104 | 105 | 106 | 107 | 108 | 109 | 110 | 111 | 112 | 113 | 114 | 115 | 116 | 117 | 118 | 119 | 120 | 121 | 122 | 123 | 124 | 125 | 126 | 127 | 128 | 129 | 130 | 131 | 132 | 133 | 134 | 135 | 136 | 137 | 138 | 139 | 140 | 141 | 142 | 143 | 144 | 145 | 146 | 147 | 148 | 149 | 150 | 151 | 152 |

Copyright © Torroid.com, 2004, Sitemap of computer articles | Resources | Computer articles home";
Page loaded in 0.661 seconds

Computer Tips   Computing Guide   Computers