apache mod_rewrite example hellow world using htaccess
apache-mod-rewrite-example-hellow-world-using-htaccess.php
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>apache mod_rewrite example hellow world using htaccess</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<meta name="Author" content="Md Iqbal Hosan">
<meta name="title" content="apache mod_rewrite example hellow world using htaccess">
<meta name="keywords" content="php, example, code, array, function, mod_rewrite, string, apache, htaccess">
<meta name="description" content="apache mod_rewrite example hellow world using htaccess">
<style>
h2, h4{background:orange; color:#000089;}
h2{ padding:3px; margin:3px; font-size:22px;}
h4{ padding:2px; margin:2px; font-size:19px;}
p{padding:2px; margin:2px; color:#0099FE;}
pre{}
div{ text-align:left;}
body{ background:#FFFFFD;}
</style>
</head>
<body>
<h2>apache mod_rewrite example hellow world using htaccess</h2>
<pre>
<?php
/*
---------------------------------------------------------------------
this is the hellow world program of a series of mod_rewrite examples
---------------------------------------------------------------------
*/
/*
-------------------------------------------------------------------------------------
TARGET : would like to redirect all request to 'hellow-world.php' of current directory
-------------------------------------------------------------------------------------
*/
/*
-------------------------------------------------------------------------------------
hellow-world.php : make a file named 'hellow-world.php' in the current directory
write : 'this is hellow world !!! redirected by .htaccess mod_rewrite' in it
-------------------------------------------------------------------------------------
*/
echo "<h4>hellow-world.php</h4>";
echo "<hr/>";
print "<p>this is hellow world !!! redirected by .htaccess mod_rewrite</p>";
/*
-------------------------------------------------------------------------------------
now make test.php : make a file named 'test.php' in the current directory
write : 'this is test' in it
-------------------------------------------------------------------------------------
*/
echo "<h4>test.php</h4>";
echo "<hr/>";
print "<p>this is test</p>";
/*
-------------------------------------------------------------------------------------------
.htaccess : make a file named 'htaccess' in the current directory
write :
<IfModule mod_rewrite.c>
RewriteEngine on
RewriteRule .* hellow-world.php
</IfModule>
in it
HOW TO MAKE .htaccess FILE ON WINDOWS : open notepad and save the page as '.htaccess'
in the current directory. Remember to put '' along with .htaccess while making the file.
-------------------------------------------------------------------------------------------
*/
echo "<h4>.htaccess</h4>";
echo "<hr/>";
print "<p><IfModule mod_rewrite.c></p>";
print "<p> RewriteEngine on</p>";
print "<p> RewriteRule .* hellow-world.php</p>";
print "<p></IfModule></p>";
/*
---------------------------------------------------------------------------
try to run 'test.php' in the browser, 'hellow-world.php' will run in fact
'test.php' is showing in the browser due to mod_rewrite
unless otherwise something goes wrong with your web server configuration.
---------------------------------------------------------------------------
*/
echo "<h4>run \"test.php\" in the browser</h4>";
?>
</pre>
</body>
</html>


No comments:
Post a Comment
leave your comments here..