Title: how to test check if mod_rewrite is enabled
Description: 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 Tutorial and Guides
Tags: mod rewrite, apache, module, test, enable, configuration, settings, check
Info: This Post Has Been Viewed 95017 Times SinceThu Jul 20, 2006 2:34 pm Author webmaster With 31 Replies #40

how to test check if mod_rewrite is enabled

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, im actually using mod_rewrite, if you look at the url in your browser, its says:

http://www.wallpaperama.com/forums/how-to-test-check-if-mod-rewrite-is-enabled-t40.html

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

http://www.wallpaperama.com/forums/viewtopic.php?t=40

if you prefer to download the full script, you can do so by downloading it at the following post:
How To Test Check If Mod_rewrite Is Enabled and download the file: Test_ModRewrite.zip

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 stpes, 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 shoulnnt 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
08p-40-mod-rewrite-1.gif

step 2. Open a blank notepad and copy and paste the following code into it:
08p-6606-mod-rewrite-php.gif

rewrite.php PHP CODE:
<h2 align=center>
<?php
// 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";}
?>
</h2>

<hr>

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

<body>
<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 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="http://www.webune.com/forums/viewtopic-p-62.html">Go back to webune forums.</a></p>
</body>
</html>


step 3. now save the file as rewrite.php in your test directory
08p-40-mod-rewrite-save.gif

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)
08p-40-mod-rewrite-httaccess.gif

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.
08p-40-mod-rewrite-ftp.gif

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
08p-40-mod-rewrite-tutorial.gif

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:


404 ERROR - If you are getting a 404 Error (Page Not Found) this means you dont have mod_rewrite on your website

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 mispelled 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.

DEMO:
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 following link:
How To Test Check If Mod_rewrite Is Enabled

or

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.

thanks.



HELP

Here are some links to help you incase 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:


please provide any comments, 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.
Comments (31)
View Top Comments
Leave Your Comments...
#1
tartanphoenix:
11 seconds ago
#177659
tartanphoenix Sun Mar 04, 2012 3:36 am
This wasn't working for me until I added this as a second line

RewriteBa /test/
#2
hauke:
1 month ago
#173709
hauke Wed Jan 11, 2012 8:37 pm
thx, for the script
#3
raven:
4 months ago
#168906
raven Mon Oct 24, 2011 9:38 pm
really handy little script - good work guys
#4
gumuruh:
4 months ago
#168382
gumuruh Sat Oct 15, 2011 9:16 pm
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?
#5
tset:
7 months ago
#161808
tset Thu Jul 14, 2011 11:46 am
php server, phpinfo visit page, search for mod rewrite.
#6
Spiros:
9 months ago
#157895
Spiros Tue May 31, 2011 9:48 am
or you can use
<?PHP
print_r(apache_get
#7
Hector:
9 months ago
#157791
Hector Mon May 30, 2011 5:21 am
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!
#8
sabastian:
1 year ago
#148597
sabastian Mon Nov 29, 2010 5:27 pm
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.
#9
kevin:
1 year ago
#140177
kevin Mon Jul 26, 2010 8:33 am
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
#10
1
MR.GREEN:
1 year ago
#135044
MR.GREEN Sat Jun 05, 2010 2:26 pm
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.

#11
3
nitish:
1 year ago
#131806
nitish Wed Apr 14, 2010 6:53 am
thanks a lot, that was helpful, i have been looking for how to use mod_rewrite.

thanks again
#12
1
dkz:
2 years ago
#128983
dkz Fri Feb 26, 2010 10:50 pm
Big thanks guys, you rescue me. ^O^
Simple but great result.
#13
james:
2 years ago
#128513
james Fri Feb 19, 2010 5:36 am
Brilliant - looked around the web for ages trying to figure out how to suss this and this really helped!
Cheers
#14
wallpaperama:
2 years ago
#125839
wallpaperama Wed Jan 13, 2010 7:33 pm
on SUN ONE, yes you can but its really hard. unless you are a unix guru otherwise i would recommend you start with LINUX
#15
mike:
2 years ago
#125838
mike Wed Jan 13, 2010 7:04 pm
does anyone know if SUN ONE supports mod rewrite or if i can install apache on a sun server?

thanks <3
#16
Icy:
2 years ago
#111365
Icy Sat Aug 01, 2009 10:57 pm
nice job - thank´s and greetings from germany :-)
#17
webmaster:
2 years ago
#102927
webmaster Sun May 10, 2009 3:07 pm
thanks, i have corrected your issues.

:)
#18
east:
2 years ago
#102858
east Sat May 09, 2009 8:36 pm
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).
#19
1
Shilpa:
2 years ago
#99309
Shilpa Sat Apr 04, 2009 10:03 am
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. ?
#20
Shilpa:
2 years ago
#99307
Shilpa Sat Apr 04, 2009 10:03 am
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. ?
Leave Your Comments...
Pages: 12
Share
| More