URL Re-Writing in PHP using Query – String

Here is Best Way to Re-Write URL using Query – String [ Dynamically]

First You must have to change into your apache httpd file

1- Go to Your apache dirc. and open httpd.conf (C:xamppapacheconfhttpd.conf)

2- Find the line #LoadModule rewrite_module modules/mod_rewrite.so and remove the hash ‘#
3- Find the block within the directory tags as indicated below and change to:
 <directory />
…….
AllowOverride None
……..
</directory>

change it to :

AllowOverride All

That’s Good!!!

4- Now We are Ready to rewrite the URL’s

5- create a file with no name but extension .htaccess.
6- this will be a file you have to place within the main directory.
7- .htaccess file have some code like-

RewriteEngine on
RewriteRule  ^news/([0-9]+)$  news.php?blog=$1
8- Now in the index.php file –

   <?php echo “<a href=’news/$id’ target=’_blank’>$news_title</a> “?>

9- In the news.php file, we can access the id by any code like –

    $get_link = $_GET[‘id’];
$query = “select * from table where id = ‘$get_link'”;
That’s All!!!

Published by Sushant Sharma

Technologist. Software Developer. Tech Analyst ।।।

Leave a comment

This site uses Akismet to reduce spam. Learn how your comment data is processed.

Design a site like this with WordPress.com
Get started