0

I'm not very good at htaccess, so looking for some help here. I have a web app running at

myserver.com/index.html

And I'm sending the requests (GET,PUT,DELETE) to a controller:

myserver.com/controller.php?id=5

Is there a way that I can use htaccess to submit through a url like

myserver.com/controller/5

I've toyed with my htaccess but just manage to create 500 errors when trying to hit the index.html page...

Fluidbyte
  • 5,162
  • 9
  • 47
  • 76

1 Answers1

1

If you send a request like: myserver.com/controller/5 and you want to use mod_rewrite to rewrite it back to /controller.php?id=5, you can use these rules:

RewriteEngine On
RewriteCond  %{REQUEST_FILENAME} !-f
RewriteCond  %{REQUEST_FILENAME} !-d
RewriteRule ^/?([^/]+)/([^/]+)$ /$1.php?id=$2 [L]

Or less general:

RewriteEngine On
RewriteCond  %{REQUEST_FILENAME} !-f
RewriteCond  %{REQUEST_FILENAME} !-d
RewriteRule ^/?controller/([^/]+)$ /controller.php?id=$1 [L]
Jon Lin
  • 142,182
  • 29
  • 220
  • 220