php,url重写,如果url没有“?”,如何从GET中获取字符串?

发布于 2024-09-19 21:37:38 字数 186 浏览 7 评论 0原文

我想建立一个 php 网站,并且想删除所有使 url 看起来动态的字符串。 但是我仍然需要通过 GET 获取信息,所以基本上我不知道该怎么做,因为我需要将参数传递给 $_GET 请求,这显然是动态的。例如,我可能有 www.domain.com/mobile_phones,其中 mobile_phones 将是我应该获取的参数/信息。 任何帮助将不胜感激

I would like to build a php website and I would like to remove all the strings that make the url to seem dynamic.
However I still need to get information through GET so basically I don't know how to do that because I need to pass a parameter to $_GET request which obviously would be dynamic . For example I may have www.domain.com/mobile_phones where mobile_phones would be the parameter/information that I should get .
Any help would be highly appreciated

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

偏闹i 2024-09-26 21:37:38

您可以通过称为“路由”的过程来完成此操作。通常,您设置重写规则以将所有内容转发到单个入口点 - index.php 然后 index.php 初始化您的应用程序,使用某种路由类。该路由类将 REQUEST_URI 与已知模式列表进行比较。当它匹配 i 模式时,它会解析出 URI 中的所有变量。

另一方面,为了在应用程序中生成正确的 URL,通常有许多帮助程序,它们采用一系列参数以及控制器/操作,并根据相同的路由规则生成 URL。

查看 Zend 框架中的 Zend_Controller 包作为一个很好的示例。

You do this through a process called "routing". Normally you set up rewrite rule to forward everything to a single entry point - index.php then index.php intializes youre application witch makes use of some kind of routing class. This routing class compares the REQUEST_URI to a list of known patterns. When it matches i pattern it takes car of parsing out all the variables form the URI.

On the other end of things, to generate the proper urls wihtin the app there are usually a number of helpers that take a series of parameters along with a controller/action and generate a URL based on the same routing rules.

Take a look at the Zend_Controller package from Zend framework for a good example.

天赋异禀 2024-09-26 21:37:38

URL 重写的工作原理是将接收到的 URL 字符串转换为更合适的格式,包括获取参数。例如,

RewriteEngine On
RewriteRule ^([0-9])/.*$ index.php?id=$1

这会将 example.com/1234/my-page 字符串转换为 example.com/index.php?id=1234 并且 id 将是可以直接从 $_GET 数组访问。

URL rewriting works by translating the received URL string into a more suitable format, including get parameters. For example

RewriteEngine On
RewriteRule ^([0-9])/.*$ index.php?id=$1

This will translate a string that's says, say example.com/1234/my-page to example.com/index.php?id=1234 and id will be accessible directly from the $_GET array.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文