本文介绍了如何在PHP中创建类似http://stackoverflow.com/posts/1807421/edit的URL?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述 29岁程序员,3月因学历无情被辞! 当您在stackoverflow.com上编辑问题时,您将被重定向到这样的URL:When you edit a question on stackoverflow.com, you will be redirected to a URL like this:但是通常应该是或怎么样我知道Stackoverflow.com不是使用PHP创建的,但是我想知道如何在PHP中实现此目标?I know that Stackoverflow.com was not created by using PHP, but I am wondering how to achieve this in PHP?推荐答案对于apache和PHP,您可以使用 mod_rewrite 规则如下:With apache and PHP, you might perform one of your examples using a mod_rewrite rule in your apache config as follows:RewriteEngine OnRewriteRule ^/posts/(\d+)/edit /posts/edit.php?id=$1这将查找纯净"形式的URL,然后将其重写,以便将其内部重定向到特定的PHP脚本.This looks for URLs of the "clean" form, and then rewrites them so that they are internally redirected to a particular PHP script.经常使用类似这样的规则将所有请求路由到一个通用控制器脚本中,该脚本可能会实例化"PostsController"类并要求其处理编辑请求.这是大多数PHP应用程序框架的常见功能.Quite often rules like this are used to route all requests into a common controller script, which might do something like instantiate a "PostsController" class and ask it to handle an edit request. This is a common feature of most PHP application frameworks. 这篇关于如何在PHP中创建类似http://stackoverflow.com/posts/1807421/edit的URL?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持! 上岸,阿里云! 08-24 03:26