我正在开发一个网站,希望为每个用户帐户创建一个唯一的url。
指
http://example.com/username => route to controler/index/username
http://example.com/username2 => route to controler/index/username2
我正在使用codeigniter,URL的模式是:
http://exaple.com/controller name/method name/argument
我不知道我们怎么能像脸书一样做这种路由??
使用CI路由,您可以非常容易地实现这一点。
在routes.php
配置(application/config/route.php)文件中,您添加了一行类似于以下行的内容:
$route['(:any)'] = "controller/index/$1";
左边的一位是您在浏览器地址栏中键入或拥有的一位。正确的位是它路由到的位置。在您的情况下,是控制器和方法的名称,后面跟着参数。对于您的案例,这将是用户。这是一个字母数字变量,所以这就是你传递它的方式。
完整的参考资料可以在这里找到,但上面的例子应该让一切都清楚:http://ellislab.com/codeigniter/user-guide/general/routing.html
参数http://exaple.com/controller_name/method_name/argument
部分在您的案例中需要是唯一的。
使用codeigniter路由可以轻松完成此操作。请查看手册:http://ellislab.com/codeigniter/user-guide/general/routing.html
您需要修改.htacce来替换index.php,例如:
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /<your_root_foler>/%{HTTP_HOST}
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ /<your_root_foler>/%{HTTP_HOST}/index.php/$1 [L]
</IfModule>
此行(RewriteRule^(.*)$//%{HTTP_HOST}/index.php/$1[L])替换应用程序中的所有index.php您在哪里使用代码点火器
之后,你可以修改你的routes.php,比如说"bottlebot"