Tutorial - How To Test Check If Mod_Rewrite Is Enabled On Your Website

Forums » Tutorial And Guides » Tutorial - How To Test Check If Mod_Rewrite Is Enabled On Your Website
this is very good and easy to follow step by step tutorial on how you can test or check to see if mod rewrite is enabled on your server for your website just follow my steps and i will show you ow to test check if mod rewrite is enabled Tutorial and Guide
HI, welcome to wallpaperama.

Apache Mod_Rewrite module is a really handy and cool feature in Apache Web Server.

With mod_rewrite, you can show a different url than the actual url. you will also help your website make it more search engine friendly by avoiding having the ? (question mark) in your urls.

for example, this topic I am writing right now here at Wallpaperama, I am actually using mod_rewrite, if you look at the url in your browser, its says:


but in reality, I am masquerading the actual php url. instead of using this url:

[UPDATE] this was my old file, i have updated my script so its no longer viewtopic.php - Im no longer using Apache for this website at this time. instead i am using NGINX but i am still masquerading my urls with nginx rewrite

if you prefer to download the full script, you can do so by downloading the attachment at the bottom of this post

otherwise, you can continue and create the files yourself:

IMPORTANT!!! - if you are going to follow this tutorial by each step, be sure to name the files as I describe, if you name them something else, the script will fail. so if you dont want to go through the steps, you can download the whole script I provided:

ok, the best way to learn is to actually do it yourself. if you have your website with a web hosting company that has mod_rewrite already enabled, then you shouldn't have any problems. Webune.com customers benefit from apache's mod_rewrite. Every customer being hosted by our shared services has automatically mod_rewrite enabled.

You can confirm if its enable by following this simple tutorial guide. In this tutorial, you will be creating two files, the first one called rewrite.php and the second one .htaccess

- I will be using Windows XP notepad to create my files. ok, lets go..

step 1. to keep this organized, create a new directory (folder) called test

step 2. Open a blank notepad and copy and paste the following code into it:

rewrite.php PHP CODE:
<h2 align=center>
// mod_rewrite Test Page
// Copyright 2006 Webune.com
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="http://www.webune.com">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 masquerading 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 change it in the .htaccess file</p>
<p>&lt;&lt; <a href="http://www.webune.com/forums/viewtopic-p-62.html">Go back to webune forums.</a></p>

step 3. now save the file as rewrite.php in your test directory

step 4. Open a new blank notepad, we are going to create a file called .htaccess

step 5. Copy and paste the following code:

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

step 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)

step 7. You should have two files in your test directory: rewrite.php and .htaccess - Now upload the test directory with the two files rewrite.php and .htaccess into your website.

step 8. Open the rewrite.php file with your browser to the location you just uploaded the files. for example: http://www.yoursite.com/test/rewrite.php

step 9. you should see two links, LINK1 and LINK2 Click on LINK1 and the same page will display.

step 10. Now click on LINK2 and the same page will display with the a mod_rewrite message. If it doesn't you either did something wrong. Check your steps. If you checked your steps, refresh your browser, and if refreshing doesn't work, then you don't have mod_rewrite enabled. if you dont have mod rewrite enabled in your server, then you might see something like this:


Troubleshoot #1:
404 ERROR - If you are getting a 404 Error (Page Not Found) this means you dont have mod_rewrite on your website or you typed the wrong url on your browser.

Troubleshoot #2:
this is the code from the .htaccess file:

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

there are some hosting companies that force you to put the absolute path. so you will have to put the absolute path of the rewrite.php file.

for example: lets say i uploaded the script to my website:

in the example above, open the .htaccess file and change the code to:
RewriteRule ^link([^/]*).html$ /test/rewrite.php?link=$1 [L]

as you can see from the code above, i have put the absolute path from the website root. so you may have mod rewrite enabled, but you have to modify the .htaccess to match your hosting company requirements.
this is how the .htaccess file would look like:
RewriteEngine On
RewriteRule ^link([^/]*).html$ /test/rewrite.php?link=$1 [L]

Advance: if you dont want to do that, you can use RewriteBase, just have to add this line after RewriteEngine On

this is how the .htaccess file would look like using RewriteBase:
RewriteEngine On
RewriteBase /test/
RewriteRule ^link([^/]*).html$ rewrite.php?link=$1 [L]

Troubleshoot #3:

500 ERROR = a 500 error means that the code you put on your .htaccess has a problem. Apache cannot process the syntax. the most common mistake people make is they type something wrong like misspelled something. so double check to make sure you have exactly the code I provided above. and be sure you have named the files as I told you.webune mod rewrite

If mod_rewrite is not working for you and you are a Webune customer, please contact our support team to assist you.

Click on this link. We have provided uploaded the files in this tutorial to show you how mod_rewrite works.

if creating the files yourself is too complicated, you can download the full script at the bottom of this post.

see a demo: mod rewrite tutorial

if you need more help, I provided some other links to other posts on this subject. hope this helps.



Here are some links to help you in case you are having trouble or its not working for you see related links

here is a short video a made to show you how you can enable on linux:

if you need more help, just leave your comments below. I would like to learn from other by telling me why you need to learn mod rewrite so I can make more of these tutorials... Now here is the download i provided if you dont want to create the files by yourself.
this is a good and helpful to show or display how to check if server has mod_rewrite. thanks
sorry but this is not a useful code since you can not test it in a code and do some other action according to this ....
most excellent! thanks for this; i needed a quick "down and dirty" test and you provided it brilliantly. =o)

sean p. o. maccath-moran
thanks very much - have been searching for something like this ..

not sure if everyone will get that:
8. pull the rewrite.php file with your browser to the location you just upoaded.
means - (put it in your browser's address bar )

thanks again

if ( in_array("mod_rewrite", apache_get_modules()) ) echo "mod rewrite on";

this is a far easier method....
very nice. it helped me!
thanks a lot for this small but very useful tool.

thanks for this - proved i'd properly implemented mod-rewrite on the apache server to my boss and it's his website that wasn't working :d
i had to add the test/ to the rule.

rewriterule ^test/link([^/]*).html$ test/rewrite.php?link=$1 [l]

or move rewrite.php into root for it to work.

i'm sure apache_get_modules() works as it is documented but for some reason it didn't work on my site. said it was undefined.
nice one. i have installed apache 1.3 on my local system. and have uncommented loadmodule and addmodule for mod_rewrite . also, allowoverride all.
restarted apache.
later placed the php file and .htaccess file as mentioned above in site. still the mod_rewrite is not working for me. could you please help. ?
this wasn't working for me until i changed the second line of rewrite.php from <? to <?php. also, the author uses both .httaccess and .htaccess in the above. i mistakenly used the former (without thinking) and ran into problems (obviously, it should be .htaccess).
thanks, i have corrected your issues.

nice job - thankĀ“s and greetings from germany :-)
does anyone know if SUN ONE supports mod rewrite or if i can install apache on a sun server?

thanks <3
on SUN ONE, yes you can but its really hard. unless you are a unix guru otherwise i would recommend you start with LINUX
Brilliant - looked around the web for ages trying to figure out how to suss this and this really helped! Cheers
Big thanks guys, you rescue me. ^O^ Simple but great result.
thanks a lot, that was helpful, i have been looking for how to use mod_rewrite. thanks again
The test works but I still can't get mysite dot com /?pr to display as mysite dot com /Busines I'm very confused how it works both ways especially if there's a strict condition or just about any condition for that matter. Please fill the gaps in my thinking thanks.
Hi and thanx very very much. finally i solve da great problem. thax. thax. and thax. you example is very useful and deep. keep your great work
hello, im kinda new to this mod rewrite business. i dont fully understand it, but i guess your tutorial showed me exactly what i needed to do. i have XAMP and it works. i can't believe it worked on the first try. now if i can just figure out how you did it.

anyways, just wanted to say thank you guys for putting this kinda stuff. keep up the good work.
Thank you for the tutorial! it really help me. I did have the mod_rewrite enabled, but this little piece of information opened my mind for other things. Thanks Again!
or you can use <?PHP print_r(apache_get
php server, phpinfo visit page, search for mod rewrite.
ya, me also... while testing it inside windows xp, enabling the LoadModule rewrite_module modules/mod_rewrite.so inside httpd.conf, and trying to create htaccess.txt inside my local directory gives me 404 result. How to solve it out?
really handy little script - good work guys
thx, for the script
This wasn't working for me until I added this as a second line RewriteBa /test/
hostlift dot com
nice keep it up.
good really doog :
I have a problem it appears "Not Found" error 404.

After open de rewrite.php, and clicking in link 2 it say that de file rewrite.php as not found in the server.
Why this is happening?
It as anything to do with a virtual server?
it means rewrite is not enabled
Nice tut man, keep the ggod work !
Fantastic!!!! just what i was looking for. i spent a week looking for something like this troubleshooting my problem. wow, im so glad i found your page. thanks for the pictures, they helped alot
I already set enabled the rewrite, now I wonder to know how can I put it in work; I mean what I have to do inside the .htaccess.

thanks in advance.
the error i am getting says:
testing mod rewrite and .htaccess file... could not validate that he .htaccess file had been created on the file server or that mod rewrite was enabled, please check and try again
Title: Tutorial - How To Test Check If Mod_Rewrite Is Enabled On Your Website [1396]
Tags: mod rewrite apache module test enable configuration settings check
Comments 34
Visits 110155