CodeIgniter htaccess 重定向
我希望这将是一个有人可以回答的简单问题。我正在寻找构建一个 CodeIgniter 应用程序,我可以在常规 PHP 中轻松构建它。
示例:我想访问 http://locahost/gregavola 并使用 htaccess 文件重写为 profile.php?用户=gregavola。我怎样才能在 CodeIgniter 中做到这一点?
通常在 htaccess 中我可以编写 ^(\w+)$ profile.php?user=$1
但这不适用于 CodeIgniter 中的路径。
有什么建议吗?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
CodeIgniter默认关闭GET参数;您应该创建一个用户控制器并将请求发送到:
然后在
user
控制器,添加以下存根:从这里您可能想要创建一个视图并将
$name
传递到其中:您可以在 CodeIgniter 用户指南,这是一个很好的入门资源。
CodeIgniter turns off GET parameters by default; instead of rewriting the URL to a traditional GET style (IE, with the
?
), you should create a user controller and send the request to:Then in the
user
controller, add the following stub:From here you would probably want to create a view and pass
$name
into it:You can find all of this in the CodeIgniter User Guide, which is an excellent resource for getting started.
要将 localhost/gregavola 映射到给定的控制器和函数,请修改 application/config/routes.php 中的路由文件,如下所示:
路由按照收到的顺序运行,因此如果您有其他路由像 localhost/application/dosomething/ 一样,您需要首先包含这些路由,以便整个应用程序中的每个页面都不会成为用户页面。
在这里阅读有关 CI 路由的更多信息: http://codeigniter.com/user_guide/general/routing.html祝
你好运!
To map
localhost/gregavola
to a given controller and function, modify the routes file at application/config/routes.php like so:Routes are run in the order they are received, so if you have other routes like localhost/application/dosomething/, you will want to include those routes first so that every page in your entire app doesn't become a user page.
Read more about CI routes here: http://codeigniter.com/user_guide/general/routing.html
Good luck!