如何用PHP重写网址?

0 php url-rewriting

让我们举例说一下我的成员之一是http://www.example.com/members/893674.php.如何让他们自定义网址,以便它可以是http://www.example.com/myname

我想我想要的是我的会员有自己的自定义网址.有没有更好的方法来重新组织我的文件.

Ste*_*dge 5

您可以使用Front Controller,它是制作自定义URL的常用解决方案,可用于所有语言,而不仅仅是PHP.这是一本指南:http://www.oreillynet.com/pub/a/php/2004/07/08/front_controller.html

基本上,您将创建一个为每个URL调用的index.php文件,其作用是解析URL并根据URL的内容确定要运行的代码.因此,在您的网站上,您的网址类似于:http://www.example.com/index.php/mynamehttp://www.example.com/index.php/about-ushttp:// www.example.com/index.php/contact-us等.为所有URL调用index.php.

您可以使用mod_rewrite从URL中删除index.php,请参阅此处:http://www.wil-linssen.com/expressionengine-removing-indexphp/