我试图从我的项目中删除index.php段,但我不能。我测试了StackOverflow中引用的几篇文章,但仍然无法。
这是我的项目结构:
(In /var/www/project directory)
project
--assets
--system
--.htaccess
--index.php
--info.php
--quickmenu.php
PHP version: 5.3.10
SO: Ubuntu 12.04
Apache version: 2.2.22
CodeIgniter: 2.1.3
我的config.php文件:
$config['base_url'] = "HTTP://".$_SERVER['HTTP_HOST']."/project/";
$config['index_page'] = "";
$config['uri_protocol'] = "REQUEST_URI";
$config['url_suffix'] = "";
$config['language'] = "portugues";
$config['charset'] = "iso-8859-1";
$config['enable_hooks'] = FALSE;
$config['subclass_prefix'] = 'MY_';
$config['permitted_uri_chars'] = 'a-z 0-9~%.:_\-';
$config['enable_query_strings'] = FALSE;
$config['directory_trigger'] = 'd'; // experimental not currently in use
$config['controller_trigger'] = 'c';
$config['function_trigger'] = 'm';
$config['log_threshold'] = '1';
$config['log_path'] = '';
$config['log_date_format'] = 'Y-m-d H:i:s';
$config['cache_path'] = '/var/ci/cache/';
$config['encryption_key'] = "q7uP3mprMYuFFvbNcXyC6uPXs2ZUezxh";
$config['sess_cookie_name'] = 'ci_session';
$config['sess_expiration'] = 7200;
$config['sess_encrypt_cookie'] = FALSE;
$config['sess_use_database'] = TRUE;
$config['sess_table_name'] = 'ci_sessions';
$config['sess_match_ip'] = FALSE;
$config['sess_match_useragent'] = TRUE;
$config['sess_time_to_update'] = 300;
$config['sess_storage'] = 'database';
$config['sess_database'] = 'default';
$config['sess_timeout'] = 7200;
$config['sess_destroy_on_timeout'] = FALSE;
$config['sess_update_interval'] = 180;
$config['sess_gc_probability'] = 10;
$config['sess_http_only'] = FALSE;
$config['sess_secure'] = FALSE;
$config['sess_forwarded_ip'] = FALSE;
$config['cookie_prefix'] = "";
$config['cookie_domain'] = "";
$config['cookie_path'] = "/";
$config['global_xss_filtering'] = FALSE;
$config['compress_output'] = FALSE;
$config['time_reference'] = 'local';
$config['rewrite_short_tags'] = FALSE;
/* End of file config.php */
/* Location: ./system/application/config/config.php */
我的.htaccess文件:
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /project/
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>
补:
网址不起作用:
http://localhost/project/#../directory/controller/method
使用这些网址:
http://localhost/project/#index.php/directory/controller/method
http://localhost/project/index.php/#directory/controller/method
答案 0 :(得分:3)
尝试将uri_protocol从AUTO更改为REQUEST_URI
$config['uri_protocol'] = "REQUEST_URI";
您可以参考以下链接:http://taggedzi.com/articles/display/codeigniter-2-htaccess-and-friendly-urls
答案 1 :(得分:1)
如果要在服务器上载,请删除RewriteBase / project /
并编写RewriteBase /
我犯了同样的错误。我刚刚测试过它。
答案 2 :(得分:1)
将您的config.php
更改为:
$config['index_page'] = "index.php";
$config['uri_protocol'] = "ORIG_PATH_INFO";
然后将此规则放在/project/.htaccess
:
RewriteEngine On
RewriteBase /project/
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.+)$ index.php/$1 [L]
还要确保.htaccess
中没有/project/directory/
。
答案 3 :(得分:0)
我解决了这个问题。
缺少在我的PHP上安装mod_rewrite包。所以在此之后只需配置config / config.php和.htaccess文件。
在我用于在我的UBUNT中安装用于PHP的mod_rewrite模块的文章下面:
How to enable mod_rewrite for Apache 2.2
感谢大家的建议,如果没有,我不会尝试这种解决方法。
答案 4 :(得分:0)
我找到了我的确切解决方案。你可以尝试一下。 我假设最重要的是RewriteBase / 和./CI/将是您的应用程序包含的文件夹名称。示例:CI /应用程序 所以要小心。
RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ ./CI/index.php/$1 [L]
但如果您是svn服务器,那么使用: RewriteRule ^(。*)$。/ index.php / $ 1 [L]
如果您使用/不使用index.php,这些将起作用 在这里``http://kabircse.tk/CI/ 或http://kabircse.tk/CI/index.php
两者都会找到你的路线控制器。如果你的路由控制器是mc,那么它会找到它http://kabircse.tk/CI/mc