0

I am completly new to htaccess, never have to do it on my own. But its time.

I have a simple PHP API, so I need redirect all urls to index.php (PHP will handle routing), so

localhost/api/user
localhost/api/post
localhost/api/whatever

Goes to

localhost/index.php

This is quite simple i gues?

RewriteRule (.*) /api/index.php

But than I need one more thing and thats, when the last sequence of url is number like:

localhost/api/user/142
localhost/api/post/675
localhost/api/whatever/2136912

It Should Go to Goes to

localhost/index.php?id=GIVEN_NUMBER

Is there even a way to do that, or should I start work on PHP solutiuon? Thanks

Bartas139
  • 15
  • 5

1 Answers1

2

Create a rule like

RewriteCond %{REQUEST_FILENAME} !-f    
RewriteRule (.*) index.php?$1 [L]

Then on index.php parse the requested URL and take your action.

Rakesh Mehta
  • 519
  • 2
  • 9