【问题标题】:removing index.php in codeigniter (works fine locally but not on the production)删除 codeigniter 中的 index.php (在本地工作正常,但在生产环境中不行)
【发布时间】:2014-06-08 10:06:52
【问题描述】:

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

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

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

但是当我将文件夹放在 prod 服务器上时,主页正在工作,但如果我想访问 http://website.com/cms_ci/content/,我会收到 404。 如果我继续http://website.com/cms_ci/index.php/content/,它正在工作。

这是我的 config 和 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]

当然在我的产品配置文件上我已经更改了

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

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

我尝试了各种 htaccess 文件,但现在我有点卡住了。

提前致谢

【问题讨论】:

  • 检查您的服务器配置是否允许 htaccess ..
  • 这里有一些链接你可以看@stackoverflow.com/questions/9234289/…
  • mod_rewrite 在我执行 phpinfo(); 时位于“加载的模块”中。但是当我在我的 htaccess 中插入垃圾代码时,我没有 500 错误...
  • 检查您的 htaccess 文件的权限
  • 你这是什么意思?

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


【解决方案1】:

试试这个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>

【讨论】:

  • 你好,我试过了,但这并没有改变任何东西。当我使用 website.com/index.php/controller/ 时,我仍然可以访问主页和其他页面。当我尝试 website.com/controller/ 时,我仍然是 404
  • 试试:website.com/index.php?/controller/
  • 无论我在 index.php 之后作为 url 放什么? (webiste.com/index.php?/controller/) 我要去主页了。
【解决方案2】:

你可以试试这个-

<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>

这应该可行!

【讨论】:

    猜你喜欢
    • 2016-07-16
    • 2018-03-23
    • 1970-01-01
    • 2019-08-17
    • 2021-12-08
    • 2014-04-27
    • 2020-04-14
    • 1970-01-01
    • 2023-01-30
    相关资源
    最近更新 更多