繁体   English   中英

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

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

我正在使用CodeIgniter v.3.0.4,无法从URL中删除“ index.php”。

  1. 我添加了.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. 在应用程序文件夹> config.php>中,将值编辑为:

     $config['index_page'] = ''; 

    和:

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

    和:

     $config['base_url'] = 'http://localhost/Project_01/'; 
  3. 我检查过我的Apache服务器conf文件在该行旁边没有井号:

     LoadModule rewrite_module modules/mod_rewrite.so 

我究竟做错了什么? 还是我在做什么?

它在CI的先前版本中运行良好,发生了什么变化?

因为您的规则是将请求发送到查询字符串,所以您需要将QUERY_STRING用于uri_protocol ,而不要使用REQUEST_URI

或者,如果您想保留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