我有下面的Url在我的示例应用程序在PHP MVC CI
http://localhost:1234/Sample/Index.php/User/index
此处用户为Controller
,索引为Action Method
我可以像下面这样写这个url吗?
http://localhost:1234/Users
看到你的代码后,你做的主要错误是你重命名了index.php
,这是错误的,请将index1212.php
恢复为index.php
剩下的事情你可以跟着其他答案走。但这是很重要的,没有index.php
文件,codeigniter将无法运行
编辑
我注意到的另一个错误,在routes.php
中,
$route['Users'] = 'user/';
not $routes
然后像这样访问你的项目,http://localhost/Sample/Users
据我所知,你不能在url中隐藏文件夹名称
如果你想使用自定义路由。http://www.codeigniter.com/user_guide/general/routing.html
你不需要在routes.php中包含index.php
// application > controllers > sample > Users.php filename first letter must be uppercase. Same with class name.
$routes['users'] = 'sample/users/index'; // Lower case preferred.
// When with out function would go straight to index function
$routes['users'] = 'sample/users';
// No Need for index.php
// $routes['Users'] = 'Sample/Index.php/User/index';
现在url将是
http://localhost:1234/project/users
http://localhost/project/users
或使用index.php
http://localhost:1234/project/index.php/users
http://localhost/project/index.php/users
你可能需要删除index.php这里有一些htaccess
https://github.com/riwakawebsitedesigns/htaccess_for_codeigniterapplication> config> config.php
$config['index_page'] = '';
htaccess例子
Options +FollowSymLinks
Options -Indexes
DirectoryIndex index.php
RewriteEngine on
RewriteCond $1 !^(index'.php|images|robots'.txt)
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php/$1 [L,QSA]
WAMP用户:如果您使用WAMP,请确保您已启用重写模块
Sample
是你的项目目录,所以你不能写你想要的路由,你可以把路由写在下面。
http://localhost: 1234/样本/用户
你的路由文件将会像下面这样:
$route['Users'] = 'User/index';