简体   繁体   English

干净的URL-从CI中的URL删除index.php无法正常工作

[英]Clean URL - removing index.php from URL in CI not working

I'm using CodeIgniter v.3.0.4 and I'm unable to remove the 'index.php' from URL. 我正在使用CodeIgniter v.3.0.4,无法从URL中删除“ index.php”。

  1. I've added the .htaccess file: 我添加了.htaccess文件:

     <ifmodule mod_rewrite.c=""> RewriteEngine On RewriteBase /project_01/ RewriteCond %{REQUEST_URI} ^system.* RewriteRule ^(.*)$ /index.php?/$1 [L] RewriteCond %{REQUEST_URI} ^application.* RewriteRule ^(.*)$ /index.php?/$1 [L] RewriteCond %{REQUEST_FILENAME} !-f RewriteCond %{REQUEST_FILENAME} !-d RewriteRule ^(.*)$ index.php?/$1 [L] </ifmodule> <ifmodule !mod_rewrite.c=""> ErrorDocument 404 /index.php </ifmodule> 
  2. In application folder > config.php > I edited the value to: 在应用程序文件夹> config.php>中,将值编辑为:

     $config['index_page'] = ''; 

    And: 和:

     $config['uri_protocol']= 'REQUEST_URI'; 

    And: 和:

     $config['base_url'] = 'http://localhost/Project_01/'; 
  3. I checked that my Apache server conf file does not have the pound sign next to the line: 我检查过我的Apache服务器conf文件在该行旁边没有井号:

     LoadModule rewrite_module modules/mod_rewrite.so 

What am I doing wrong? 我究竟做错了什么? Or what am I not doing? 还是我在做什么?

It worked fine in prior versions of CI, what changed? 它在CI的先前版本中运行良好,发生了什么变化?

Because your rule is sending the request to the query string, you need to use QUERY_STRING for the uri_protocol , and not REQUEST_URI . 因为您的规则是将请求发送到查询字符串,所以您需要将QUERY_STRING用于uri_protocol ,而不要使用REQUEST_URI

As an alternative, and if you would like to keep REQUEST URI , you can change the rule to either one of the following: 或者,如果您想保留REQUEST URI ,则可以将规则更改为以下任一选项:

RewriteRule ^(.*)$ index.php/$1 [L]
RewriteRule ^ index.php [L]

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM