Tuesday, 4 June 2013

Url Rewriting Using .htaccess

Url rewriting: there are two type  urls according to my is absolute url and other is relative absolute url we are define the path of server in a variable.(.htaccess file,absolute url,mod rewriting in .htaccess)

Step 1: Create a config file for database connectivity (config.php)



Step 2:now cteate a php link file

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "">
<html xmlns="">
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title>Untitled Document</title>

              $rs=mysql_query("select * from table_name");
               while($row=mysql_fetch_array($rs)) { ?>
                   <a href="<?php echo $path."/search/".$row["name"]."-".$row["id"];  ?>"><?php echo $row["name"]; ?></a>
<?php }           


Step 3: Create a .htaccess file

Options +FollowSymLinks

RewriteEngine on

RewriteBase /

RewriteRule ^search/(.*)-([0-9]+)$ search.php?name=$1&id=$2 [NC,L]

Step 4:now use this data into search.php page

         echo $_GET["name"];
     echo  $_GET["id"];

No comments: