0

So I have a php file called lets say "foo.php". I want foo.php to act as a controller (like in a MVC Framework except I am using regular PHP). So lets say when a user goes to url.com/foo.php/1, I want it to do the same thing as foo.php?id=1

Would I handle something like this in the .htaccess or is it possible to do it just via the foo.php file?

raeq
  • 971
  • 4
  • 15
  • 36
  • possible duplicate of [Hidden features of mod\_rewrite](http://stackoverflow.com/questions/286004/hidden-features-of-mod-rewrite) – AeroX May 01 '14 at 15:45
  • Yes, assuming your using Apache webserver you would need to use `mod_rewrite` and a `.htaccess` file for this – AeroX May 01 '14 at 15:46
  • This sounds like a simple mod-rewrite in htacces. I suggest following some tutorial at the internet which give you some basics on MVC an clean URL like [this one](http://www.youtube.com/watch?v=ZbBf4jfwWko) – Daniel May 01 '14 at 16:01

1 Answers1

0

Since you mentioned MVC, it sounds like what you're really after is a Front Controller.

Here is a nice tutorial to get you started: Front Controller Pattern.

Basically it's a combination of PHP and .htaccess. The .htaccess file routes ALL requests to foo.php, which then translates the url parameters as follows:

example.com/controller/method/param1/param2/etc...
mister martin
  • 6,197
  • 4
  • 30
  • 63