Sunday, March 16, 2014

How to create simple mod_rewrite example (using uWamp and XAMPP)


-----
How to create simple mod_rewrite example (using uWamp and XAMPP)

INTRODUCTION


The mod_rewrite module uses a rule-based rewriting engine, based on a PCRE regular-expression parser, to rewrite requested URLs on the fly. By default, mod_rewrite maps a URL to a filesystem path. However, it can also be used to redirect one URL to another URL, or to invoke an internal proxy fetch.
mod_rewrite provides a flexible and powerful way to manipulate URLs using an unlimited number of rules. Each rule can have an unlimited number of attached rule conditions, to allow you to rewrite URL based on server variables, environment variables, HTTP headers, or time stamps.
mod_rewrite operates on the full URL path, including the path-info section. A rewrite rule can be invoked in httpd.conf or in .htaccess. The path generated by a rewrite rule can include a query string, or can lead to internal sub-processing, external request redirection, or internal proxy throughput.




STEPS

1) In the example folder that you have created in the previous tutorial, create a new folder “modrewrite”.
2) We are going to create three files as follows:
.htaccess
# Redirect everything in this directory to "page1.php"
RewriteEngine on
RewriteRule .* page1.php
index.php
<html >
<head>
        <title>Without Rewrite</title>
</head>
<body>
        <h1>Info</h1>
        <p>Your site doesn't allow mod_rewrite</p>
</body>
</html>
page1.php
<html >
<head>
        <title>With mod_rewrite</title>
</head>
<body>
        <h1>Info</h1>
        <p>Your site allows mod_rewrite</p>
</body>
</html>
3) In the UwAmp Control Panel, under the section Configuration, click “Apache Config” button.
4) When the Apache Config dialog window pops up, click Modules tab.
4.1) Select the check box for rewrite module.
Click Ok.
5) The UwAmp will automatically restart.
7) Repeat Step 3 and 4. But now, deselect the check box for rewrite_module.
8) The UwAmp will automatically restart.

10) Now delete the .htaccess file that you have created in Step 2.
11) Refer tutorial http://secure-steps.blogspot.com/2014/03/how-apache-and-php-works.html. Can you apply this rewrite exercise to the XAMPP15 server?



FURTHER EXERCISES




REFERENCES


No comments:

Post a Comment