CodeIgniter的htaccess和URL重写问题
我从来没有使用过CodeIgniter,更不用说任何PHP框架,我想我会试试看。 一切都很好,除了我似乎无法从URL中删除index.php,仍然访问我的网页。
我从来没有使用MVC结构,所以我正在学习,所以如果我做错了,请原谅我。
我试图通过简单地inputlocalhost / ci / about访问我创build的名为'about_page.php'的视图,但是目前我只能通过使用localhost / ci / index.php / about
 该页面的控制器是: /application/controllers/about.php 
 该页面的模型是: /application/models/about_model.php 
 而该页面的视图是: /application/views/about_page.php 
我已经find了解决这个问题的方法,但一直没有find答案。 这是我已经搜查的地方:
  CodeIgniter  – 删除index.php 
  Codeigniter  – 如何从url中删除index.php? 
  http://www.farinspace.com/codeigniter-htaccess-file/ 
 CodeIgniter在“应用程序”文件夹中提供了一个.htaccess文件,其中只包含“ Allow Deny From All 。 所以我在根目录下创build了一个新的.htaccess文件, http://localhost/ci/.htaccess并添加了这个代码: 
 RewriteEngine On RewriteBase /ci RewriteCond %{REQUEST_FILENAME} !-f RewriteCond %{REQUEST_FILENAME} !-d RewriteRule ^(.*)$ index.php/$1 [L] 
当.htaccess文件位于根目录时,我得到一个500内部服务器错误。 当我将完全相同的文件复制到应用程序文件夹500错误消失,但我仍然无法通过使用localhost / ci / about访问关于页面
 我已经改变$config['index_page'] = 'index.php'; 到$config['index_page'] = ''; 我试着改变$config['uri_protocol'] = 'AUTO'; 到$config['uri_protocol'] = 'REQUEST_URI'; 但我仍然收到内部服务器错误。 
我进入了httpd.conf文件,取消了mod_rewrite.so模块的注释,所以我知道mod_rewrite是活动的。
有没有人有任何想法,为什么这不工作,或者我怎么能得到这项工作? 我知道在这个问题上有很多关于StackOverflow的问题,但我找不到解答我的问题的问题。
我做对了吗? 我甚至可以通过访问localhost / ci / about访问about页面,还是必须在“application”目录下创build一个“about”目录?
 有3个步骤来删除index.php 。 
- 
在 application/config.php文件中进行以下更改$config['base_url'] = 'http://'.$_SERVER['SERVER_NAME'].'/Your Ci folder_name'; $config['index_page'] = ''; $config['uri_protocol'] = 'AUTO';
- 
使用下面的代码在根目录下制作 .htaccess文件RewriteEngine on RewriteCond $1 !^(index\.php|resources|robots\.txt) RewriteCond %{REQUEST_FILENAME} !-f RewriteCond %{REQUEST_FILENAME} !-d RewriteRule ^(.*)$ index.php/$1 [L,QSA]
- 
启用重写引擎(如果尚未启用) 一世。 首先,用下面的命令启动它: a2enmod rewriteII。 编辑文件 /etc/apache2/sites-enabled/000-default将所有 AllowOverride None更改为AllowOverride All。注意:在最新版本中,您需要更改 /etc/apache2/apache2.conf文件III。 使用以下命令重新启动服务器: sudo /etc/init.d/apache2 restart
 您的.htaccess稍微closures。 看我的: 
  RewriteEngine On RewriteBase /codeigniter RewriteCond %{REQUEST_FILENAME} !-f RewriteCond %{REQUEST_FILENAME} !-d RewriteCond $1 !^(index\.php|images|robots\.txt|css|docs|js|system) RewriteRule ^(.*)$ /codeigniter/index.php?/$1 [L] 
注意“codeigniter”在两个地方。
之后,在你的configuration中:
 base_url = "http://localhost/codeigniter" index = "" 
无论何种情况,都要将codeigniter更改为“ci”
 <IfModule mod_rewrite.c> RewriteEngine On RewriteBase /dmizone_bkp RewriteCond %{REQUEST_FILENAME} !-f RewriteCond %{REQUEST_FILENAME} !-d RewriteCond $1 !^(index\.php|images|robots\.txt|css|docs|js|system) RewriteRule ^(.*)$ /dmizone_bkp/index.php?/$1 [L] </IfModule> 
这对我有用
将你的.htaccess文件移动到根文件夹(在我的情况下,find应用程序文件夹之前)
 RewriteEngine on RewriteBase /yourProjectFolder RewriteCond %{REQUEST_FILENAME} !-f RewriteCond %{REQUEST_FILENAME} !-d RewriteRule .* index.php/$0 [PT,L] 
我的config.php看起来像这样(application / config / config.php )
 $config['base_url'] = ""; $config['index_page'] = "index.php"; $config['uri_protocol'] = "AUTO"; 
让我知道它是否也为你们工作! 干杯!
如果不工作
 $config['uri_protocol'] = 'AUTO'; 
改变它
 $config['uri_protocol'] = 'PATH_INFO'; 
如果不工作改变它
 $config['uri_protocol'] = 'QUERY_STRING'; 
如果使用这个
 $config['uri_protocol'] = 'ORIG_PATH_INFO'; 
与redirect或标题的位置url不在htaccess中将无法正常工作,你必须在htaccess工作的url
对于那些使用wamp服务器的用户,请按照@Raul Chipad解决scheme的前两个步骤操作:
- 点击wamp图标(通常是绿色),进入“Apache”>“Apache模块”>“rewrite_module”。 应该勾选“rewrite_module”! 然后这是要走的路!
我正在使用这样的 – codeigniter-htaccess文件 ,它是一个很好的文章开始。
- 将.htaccess文件保留在CI根目录中
- 确保mod_rewrite是打开的
- 检查错别字(即控制器文件/类名)
-  在/application/config/config.php中设置$config['index_page'] = "";
-  在/application/config/routes.php设置你的默认控制器$route['default_controller']="home";
如果您正在运行CI(2.1.3)的全新安装,则没有太多可能是错误的。
- 2configuration文件
- 调节器
- 的.htaccess
- mod_rewrite的
读
- Codeigniter .htaccess
- redirect指数的PHPfunction于笨
只需在.htaccess文件中添加:
 DirectoryIndex index.php RewriteEngine on RewriteCond $1 !^(index\.php|images|css|js|robots\.txt|favicon\.ico) RewriteCond %{REQUEST_FILENAME} !-f RewriteCond %{REQUEST_FILENAME} !-d RewriteRule ^(.*)$ ./index.php?/$1 [L,QSA]