URL Rewrite in PHP like in Smarty Template [closed]
I am banging my head from a couple of days to use the URL rewriting for a core php website. Previously the website was developed using smarty, but due to some limitations, I am redoing it in core PHP. The problem is that smarty is using some templates code to create the Pretty URL's which I am not able to do in core PHP. Like in this example. http://amitgharat.blogspot.com/
Is any开发者_运维问答 body came across this kind of problem and save me, or any idea or suggestion please. I will be really thank full.
Regards,
I think what you need need is a "front controller" ref: http://www.phppatterns.com/docs/design/the_front_controller_and_php
Essentially what happens is this:
Assuming your site will have this url structure:
http://www.example.com/page/1
A .htaccess file redirects all requests to a file (index.php). You can of course write your .htaccess file so that files that do exist with certain extensions (.jpg etc) are not redirected.
In your index.php you can access the "page/1" part from your url via the
$_SERVER['PHP_SELF']
variable.
When you then do from there is up to you. For example, you might break that up into an array using explode()
, do some more parsing and finally dispatch the requested call.
If you haven't already looked at the mvc pattern, I reckon it would be worth while looking at that.
Having said that, there are quite a few nice PHP frameworks out there (code igniter, symfony, etc) which can allow you to code up that site quickly.
精彩评论