1. Open a blank notepad document
2. Copy and paste the following code into the blank notepad
2. Copy and paste the following code into the blank notepad
You are not using mod_rewrite - Try LINK2';} elseif($_GET['link']==2){echo'Congratulations!! You are using Apache mod_rewrite';} else{echo 'Linux Apache mod_rewrte Tutorial';} ?>
LINK 2 = LINK 2 - Yes, Uses Apache's Mod Rewrite using this URL:: link2.html
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 mascaraing 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
NOTE: when you click on LINK2, you should see a message that says: Congratulations!! You are using Apache mod_rewrite
500 ERROR: If you get a 500 Error, this means you made a typo or mistake creating the files OR you are not allowed to use .htaccess
404 ERROR: if you get a 404 error, then this means you do not have Mod_Rewrite on this server.
3. Now Save the file as "rewrite.php"
4. Now create a file called .htaccess - to make this type of file, open another blank notepad document
5. Copy and paste the following code into the .htaccess file:
RewriteEngine On
RewriteRule ^link([^/]*).html$ rewrite.php?link=$1 [L]
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 .htaccess 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. Open the rewrite.php file with your browser to the location you just uploaded. for example:
http://www.your_website.com/test/rewrite.php
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 or you dont have permission to run .htaccess files on your website. talk to your web hosting company to make sure they allow apache .htaccess - Some hosting companies do not allow .htaccess because some people take advantage of this feature, so many web hosting companies block their users from using. so check with them
If you get a 500 Error, then you do not have mod_rewrite enabled in your server.