我的 code igniter 安装中的索引页(又名 homepage.php)无论如何都工作正常。
问题在于使用子目录来存储其他页面,目前它的设置如下:
加载像 http://localhost/VAw_CI/
这样的主页工作正常(加载 homepage.php),这是在 routes.php 中设置的:
$route['default_controller'] = "pages/homepage";
在 config.php 中,我设置了:
$config['base_url'] = 'http://localhost/VAw_CI';
/*
|--------------------------------------------------------------------------
| Index File
|--------------------------------------------------------------------------
|
| Typically this will be your index.php file, unless you've renamed it to
| something else. If you are using mod_rewrite to remove the page set this
| variable so that it is blank.
|
*/
$config['index_page'] = '';
我在上面指定了 $config['index_page'] = '';
,因为我修改了位于 htdocs
中的 .htaccess,例如:
RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule .*homepage/$0 [PT,L]
但是,如果我尝试登录 homepage.php,它目前看起来像:
它将我发送到 http://localhost/VAw_CI/pages/clientlogin
显示:
我的 Controller 设置如下:
这里有什么?当我访问 http://localhost/VAw_CI
时,它正在有效地正确加载 views->pages->homepage.php
View ,但似乎任何其他 View 都没有在我的例子中,除了索引 (homepage.php) 之外,我是否在某处缺少一些页面其他 的路径设置?
最佳答案
请在项目文件夹中创建 .htaccess 文件并写入:
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
# Rewrite all other URLs to index.php/URL
RewriteRule ^(.*)$ index.php?url=$1 [PT,L]
</IfModule>
<IfModule !mod_rewrite.c>
ErrorDocument 404 index.php
</IfModule>
你不需要在配置文件的base_url中定义:
$config['base_url'] = ''; // blank it.
关于php - 本地主机 (XAMPP) 中路径的 Codeigniter 问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13146395/