How to create simple mod_rewrite example (using uWamp and XAMPP)
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.
This tutorial continues from http://secure-steps.blogspot.com/2014/03/how-to-create-virtual-host-on-apache.html
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.
6) Browse http://www.example.local/modrewrite
7) Repeat Step 3 and 4. But now, deselect the check box for rewrite_module.
8) The UwAmp will automatically restart.
9) Browse http://www.example.local/modrewrite
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?
1) http://httpd.apache.org/docs/current/mod/mod_rewrite.html
2) http://www.askapache.com/htaccess/mod_rewrite-basic-examples.html
3) http://www.sitepoint.com/apache-mod_rewrite-examples-2/
4) http://www.noupe.com/php/10-mod_rewrite-rules-you-should-know.html