Modify .htaccess for query strings

37 views Asked by At

This is my working directory

das
|__views
   |__admin
   |__doctor
   |__user
      |__find-doctor.php
      |__process.php
      |__show-result.php
   |__index.php(landing page)
|__index.php(routing)
|__.htaccess

The .htaccess I have right now is

RewriteEngine On
RewriteBase /
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /das/index.php [L]

I need to modify the htaccess file to send query strings like

localhost/user?doctor-id=2

so that I can use the id from URL for querying database

1

There are 1 answers

0
SJacks On

In .htaccess

 RewriteCond %{REQUEST_FILENAME} !-f
 RewriteRule ^index/([0-9a-zA-Z]+)-([0-9]+) .php?user=$1&id=$2 [NC,L]

PHP

 <?php
 $get_param_one = $_GET['user'];
 $get_param_two = $_GET['id'];

 echo $get_param_one;
 echo $get_param_two;
 ?>

Example URL: https://example.com?user=doctor&id=who

get_param_one = doctor
get_param_two = who