删除codeigniter中的index.php(在本地工作正常,但不在生产中)

时间:2014-04-23 13:57:04

标签: php .htaccess codeigniter-2 codeigniter-routing

我花了很多时间寻找答案但发现没有人有同样的问题:)。

我的本​​地版本很好(在ampps上运行),没有index.php的网址效果很好。 我的本地和prod文件夹都在子文件夹中,所以它就像:

http://localhost/ci/
http://website.com/cms_ci/

但是,当我将我的文件夹放在prod服务器上时,主页正在运行,但如果我想要到达http://website.com/cms_ci/content/我就得到了404。 如果我继续http://website.com/cms_ci/index.php/content/,那就可以了。

以下是我的配置和htaccess文件的设置:

config.php

$config['base_url'] = 'http://localhost:8080/cms/'; 
$config['index_page'] = '';
$config['uri_protocol'] = 'AUTO';
$config['url_suffix'] = '';

htaccess的

Options -Indexes
   RewriteEngine on
   RewriteCond $1 !^(index\.php|assets/|robots\.txt)
   RewriteRule ^(.*)$ index.php/$1 [L]

当然,在我的prod配置文件中,我已经改变了

$config['base_url'] = 'http://localhost:8080/cms/'; 

$config['base_url'] = 'http://www.website.com/cms_ci/'; 

我尝试了所有类型的htaccess文件,但现在我有点被困了。

提前致谢

2 个答案:

答案 0 :(得分:0)

试试这个htaccess:

<IfModule mod_rewrite.c>
    RewriteEngine On
    RewriteBase /

    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>

答案 1 :(得分:0)

你可以试试这个 -

<IfModule mod_rewrite.c>
RewriteEngine On

RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d

RewriteCond $1 !^(index\.php|public|img|images|js|fonts|assets|robots\.txt|css)
RewriteRule ^(.*)$ index.php/$1 [L]

</IfModule>

这应该有效!

相关问题