开发者

URL Rewrite in PHP like in Smarty Template [closed]

开发者 https://www.devze.com 2023-03-29 11:57 出处:网络
It's difficult to tell what is being asked here. This question is ambiguous, vague, incomplete, overly broad, or rhetorical andcannot be reasonably answered in its current form. For help clari
It's difficult to tell what is being asked here. This question is ambiguous, vague, incomplete, overly broad, or rhetorical and cannot be reasonably answered in its current form. For help clarifying this question so that it can be reopened, visit the help center. Closed 11 years ago.

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.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号