Mod_rewrite : apache config settings for Mod_rewrite

Published by

Posted on August 04, 2008

Test script
1. Create a php file called “rewrite.php” with your text editor (notepad)
2. Copy and paste the following code into rewrite.php
<h2 align=center>
// mod_rewrite Test Page
// Copyright 2006
if($_GET[‘link’]==1){echo”You are not using mod_rewrite”;}
elseif($_GET[‘link’]==2){echo”Congratulations!! You are using Apache mod_rewrite”;}
else{echo”Linux Apache mod_rewrte Test Tutorial”;}


<title>How To Test mod_rewrite in Apache Linux Server</title>

<p align=”center”>by <a href=””>Webune</a></p>
<p><a href=”rewrite.php?link=1″>LINK1</a> = rewrite.php?link=1</p>
<p><a href=”link2.html”>LINK2</a> = link2.html</p>
<p>How this works: both links are for this same page, except they both are different. link one is without the mod_rewrite and link2 is using mod_rewrite. Link1 show the php file, with with mod_rewrite we are mascarading the php file into a html file. you can use whatever type of extension you want, you can change it to .htm or .shtml etc… all you have to do is to make sure you also chang it in the .htaccess file</p>
<p>&lt;&lt; <a href=””>Go back to webune forums.</a></p>

3. Save rewrite.php
4. Now create a file called .htaccess with your text editor like notepad
5. Copy and paster the following code into the .htaccess file:

RewriteEngine On
RewriteRule ^link([^/]*).html$ rewrite.php?link=$1 [L]


6. Save as .htaccess (if you are using notepad as I am, make sure to put quotes in between. example: “.htaccess” otherwise, notepad will create a file called .htacces.txt and we don’t need the .txt at the end only .htaccess)
7. Now upload these two file into a new directory in your site. for example: test
8. Pull the rewrite.php file with your browser to the location you just upoaded.
9. you should see two links, LINK1 and LINK2 Click on LINK1 and the same page will display.
10. Now click on LINK2 and the same page will display with the a mod_rewrite message. If it doesnt you either did something wrong. Check your steps. If you checked your steps, refresh your browser, and if refreshing doesnt work, then you dont have mod_rewrite enabled.


========== enabling mod_rewrite =======

<Directory "/home/htdocs">    **replace with your actual path
	Options +FollowSymLinks
	AllowOverride AuthConfig FileInfo
The directive-type can be one of the following groupings of directives.
Allow use of the authorization directives (AuthDBMGroupFileAuthDBMUserFileAuthGroupFileAuthNameAuthType,AuthUserFileRequireetc.).
Allow use of the directives controlling document types (DefaultTypeErrorDocumentForceTypeLanguagePrioritySetHandler,SetInputFilterSetOutputFilter, and mod_mime Add* and Remove* directives, etc.).
Allow use of the directives controlling directory indexing (AddDescriptionAddIconAddIconByEncodingAddIconByType,DefaultIconDirectoryIndexFancyIndexingHeaderNameIndexIgnoreIndexOptionsReadmeNameetc.).
Allow use of the directives controlling host access (AllowDeny and Order).
Allow use of the directives controlling specific directory features (Options and XBitHack).

Apache features