PHP : Check if mod_rewrite is activated on your server

Web Programming Forum : PHP, ASP, JAVA etc.

PHP : Check if mod_rewrite is activated on your server

Postby Alex on Sat Jan 12, 2008 7:07 pm

1. Create a php file called "rewrite.php" with your text editor (notepad)
2. Copy and paste the following code into rewrite.php

Code: Select all
<h2 align=center>
<?
// mod_rewrite Test Page
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>


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:

Code: Select all
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.
User avatar
Alex
Site Admin
 
Posts: 464
Joined: Thu Dec 20, 2007 1:31 pm
Location: CrazyLeaf HQ

Re: PHP : Check if mod_rewrite is activated on your server

Postby rick22 on Mon Feb 11, 2008 12:08 pm

thanx for dis alex.... :)
rick22
Junior Member
 
Posts: 16
Joined: Mon Feb 11, 2008 7:54 am

Re: PHP : Check if mod_rewrite is activated on your server

Postby Alex on Mon Feb 11, 2008 12:12 pm

rick22 wrote:thanx for dis alex.... :)


Glad we could help
User avatar
Alex
Site Admin
 
Posts: 464
Joined: Thu Dec 20, 2007 1:31 pm
Location: CrazyLeaf HQ

Re: PHP : Check if mod_rewrite is activated on your server

Postby Hickeroar on Thu Apr 03, 2008 12:14 pm

You can also do this with a single line of php code and no .htaccess file.

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

If it's on, "Mod rewrite on" will appear.

Just thought I'd throw that out there. :-P
Hickeroar
Junior Member
 
Posts: 2
Joined: Thu Apr 03, 2008 12:12 pm

Re: PHP : Check if mod_rewrite is activated on your server

Postby Alex on Fri Apr 04, 2008 8:58 am

Hickeroar wrote:You can also do this with a single line of php code and no .htaccess file.

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

If it's on, "Mod rewrite on" will appear.

Just thought I'd throw that out there. :-P


Thanks for the addition.
User avatar
Alex
Site Admin
 
Posts: 464
Joined: Thu Dec 20, 2007 1:31 pm
Location: CrazyLeaf HQ

Re: PHP : Check if mod_rewrite is activated on your server

Postby webdesign on Tue Apr 22, 2008 7:34 am

Thanks alex for describing php.hope i will use it.
User avatar
webdesign
Full Member
 
Posts: 65
Joined: Tue Apr 01, 2008 8:59 am


Return to Programming Forum

Who is online

Users browsing this forum: No registered users and 0 guests

cron