0

i'm looking for a technique to rewrite the index.php?page=users&id=1 to /users/1/. I found some snippets for my .htaccess but nothing worked for me. I also reading rewrite doc

I've got $_GET['page'] in my root index.php so my url is index.php?page=users and inside my users.php i've got $_GET['id'] so my url is index.php?page=users&id=1

How do I get with rewrite /users/4/

Tried rule is:

RewriteRule ^([0-9]+)\/([0-9]+)$ index.php?page=$1&id=$2
RavinderSingh13
  • 130,504
  • 14
  • 57
  • 93
  • You want to change the links to `/users/#` then do a rewrite rule. Please add what you've tried so we can advise how to change it. – user3783243 Jul 14 '21 at 22:47
  • i've tried this one `RewriteRule ^([0-9]+)/([0-9]+)$ index.php?page=$1&id=$2`, [this](https://stackoverflow.com/questions/11696718/htaccess-rewrite-book-phpid-1234-to-book-1234) one – PhilvanGaat Jul 14 '21 at 22:59
  • Do you know what that says? `([0-9]+)/([0-9]+)` <> `/users/4/` Good place to test regexs https://regex101.com/ – user3783243 Jul 14 '21 at 23:02
  • regex said there must be a backslash between `([0-9]+)/([0-9]+)` so this is what it looks now `RewriteRule ^([0-9]+)\/([0-9]+)$ index.php?page=$1&id=$2` but it still won't work. if i type `/users/1` i've got a blank page – PhilvanGaat Jul 14 '21 at 23:31
  • Now im trying [this](https://stackoverflow.com/a/26295608/12004521) one and it won't work too – PhilvanGaat Jul 15 '21 at 02:04
  • 1
    `[0-9]+` matches multiple digits from 0 through 9, and you have put that in the place where your URL actually contains `users`, so of course this doesn’t match. – CBroe Jul 15 '21 at 06:25
  • Ok, someone deleted his comments. My actual .htaccess is following ``RewriteEngine on RewriteBase /driver RewriteCond %{REQUEST_FILENAME} !-f RewriteCond %{REQUEST_FILENAME} !-d RewriteRule ^(.*)$ index.php?page=$1 [L,QSA] RewriteRule ^([\w-]+)/(\d+)/?$ index.php?page=$1&id=$2 [QSA,L]`` and i want ``index.php?page=users&id=1`` to ``/users/1`` and ``index.php?page=home`` to ``/home`` – PhilvanGaat Jul 18 '21 at 19:02

0 Answers0