0

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
    These GET parameters are per default preserved by the rewriting rules. You can already use them in PHP. If not, so if you have some very exotic setup, then add the documented `QSA` flag. – arkascha Aug 27 '20 at 16:40
  • 1
    Does this answer your question? [Reference: mod\_rewrite, URL rewriting and "pretty links" explained](https://stackoverflow.com/questions/20563772/reference-mod-rewrite-url-rewriting-and-pretty-links-explained) – BadHorsie Aug 27 '20 at 16:53
  • @BadHorsie it doesn't answer my question specifically but I got the idea of how the system works thanks –  Aug 28 '20 at 06:22

1 Answers1

0

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

SJacks
  • 360
  • 1
  • 17