Codeigniter - 如何从url删除index.php? [英] Codeigniter - how to remove the index.php from url?

查看:250
本文介绍了Codeigniter - 如何从url删除index.php?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有以下的项目结构

/system
/applications
  /cache
  /core
  /helpers
  /hook
  /language
  /libraries
  /logs
  /third_party
  /admin-panel
     /config
     /controllers
        welcome.php
        dashboard.php
     /errors
     /models
     /views
        welcome.php
        dashboard.php
  /user-panel
     /config
     /controllers
            welcome.php
            dashboard.php
     /errors
     /models
     /views
        welcome.php
        dashboard.php
/admin
  index.php
index.php

我的index.php在我的项目文件夹中有用户面板作为我的应用程序文件夹和index.php在admin文件夹有admin面板应用程序文件夹。

My index.php inside my project folder has user-panel as my application folder and index.php in admin folder has admin-panel as my application folder.

我插入了这行
$ route ['default_controller'] =welcome;
$ route ['welcome'] ='welcome';
在用户面板和管理面板内的routes.php

I have inserted this line $route['default_controller'] = "welcome"; $route['welcome'] = 'welcome'; in routes.php inside both user-panel and admin-panel

我可以访问用户面板和管理面板的欢迎控制器,使用 http:// localhost / myproject和http:// localhost / myproject / admin

I can access welcome controller of my both user-panel and admin-panel by using http://localhost/myproject and http://localhost/myproject/admin

控制器使用 http:// localhost / myproject / dashboard或http:// localhost / myproject / admin / dashboard

我的信息中心控制台可通过使用 http://localhost/myproject/index.php/dashboard或http://localhost/myproject/admin/index.php/dashboard

my dashboard controller is accessible by using http://localhost/myproject/index.php/dashboard or http://localhost/myproject/admin/index.php/dashboard

但我不想索引.php包含在我的网址。我想删除它。我也试过在我的admin文件夹中使用.htaccess。我在这里写下面这行

But i dont want index.php included in my url. I want to remove it. I have also tried by using .htaccess inside my admin folder. I write following line in this

RewriteEngine On
RewriteCond $1 !^(index\.php|(.*)\.swf|robots\.txt)
RewriteRule ^(.*)$ index.php/$1 [L]

但这对我没有用。它给404找不到CI错误。我也启用mod_rewrite通过改变AllowOerride None到AllowOverride All在httpd.conf。请告诉我应该怎么做来删除index.php,我应该把我的.htaccess文件放在我的项目目录中。

but this didn't work for me. It give 404 not found CI error. I have also enabled mod_rewrite by changing AllowOerride None to AllowOverride All in httpd.conf. Please tell me what should i do to remove index.php and where should i place my .htaccess files in my project directory.

推荐答案

如果项目的根文件夹不是域的根,即您的网站是域 http:// localhost / myproject 的子目录,则您的.htaccess中需要一个额外的行文件 RewriteBase

if your root folder for project is not root of domain i.e. your website is subdirectory of a domain http://localhost/myproject then you need an additional line in your .htaccess file that is RewriteBase

RewriteEngine On
RewriteBase /myproject
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php/$1 [L]

同时确保你的config.php配置为

Also make sure, your config.php is configured as

$config['base_url'] = 'http://localhost/myproject/';
$config['index_page'] = '';

并且mod_rewrite在apache的配置文件中启用。

And mod_rewrite is enable in apache's config file.

这篇关于Codeigniter - 如何从url删除index.php?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆