【问题标题】:remove index.php in codeigniter. my project is in subfolder删除 codeigniter 中的 index.php。我的项目在子文件夹中
【发布时间】:2016-02-03 20:40:44
【问题描述】:

我正在尝试删除 codeigniter 中的 index.php。我的 codegiter 项目位于 public_html/programemis/lasoona/ 中。我的 .htacess 文件包含以下代码。

RewriteEngine on
RewriteBase /lasoona/
RewriteCond $1 !^(index.php|resources|robots.txt)
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php/$1 [L,QSA]

但它不起作用。请任何人帮忙。

【问题讨论】:

  • 这对我来说没问题,你得到的是 404 吗?你定义了base_url 吗? $config['index_page']呢,是空的吗?
  • 好点@kisaragi .... 添加一件事删除 QSA
  • $config['index_page'] 为空但仍无法正常工作
  • index.php/$1 会产生index.php/foo/bar,这不会是一个有效的 url,除非你启用了 path_info。也许你想要index.php?$1

标签: php .htaccess codeigniter


【解决方案1】:

试试这个:

RewriteEngine on
RewriteBase /programemis/lasoona/
RewriteCond $1 !^(index.php|resources|robots.txt)
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ /programemis/lasoona/index.php?/$1 [L,QSA]

【讨论】:

  • 亲爱的@aeonsleo,也试试这个,但还是不行。
【解决方案2】:

网上已经发布了很多解决方案。这是来自stackoverflow本身:

Codeigniter remove index.php - htaccess localhost

如果它不起作用,这是另一个(这对我有用)基于:

https://docs.expressionengine.com/latest/urls/remove_index.php.html

<IfModule mod_rewrite.c>
        RewriteEngine On
        RewriteCond %{THE_REQUEST} ^GET.*index\.php [NC]
        RewriteCond %{REQUEST_URI} !/system/.* [NC]
        RewriteRule (.*?)index\.php/*(.*) /$1$2 [R=301,NE,L]
        RewriteCond %{REQUEST_FILENAME} !-f
        RewriteCond %{REQUEST_FILENAME} !-d
        RewriteRule .* index.php/$0 [PT,L]
</IfModule>

请注意 .htaccess 的位置。

【讨论】:

    【解决方案3】:

    我正在使用它并尝试它。如果不起作用,请从 RewriteBase 中删除 programemis 文件夹。如果您遇到同样的问题,我建议您创建一个子域。

    RewriteEngine on
    RewriteBase /programemis/lasoona/
    RewriteRule ^(application|system|\.svn) index.php/$1 [L]
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteRule ^(.*)$ index.php/$1 [QSA,L]
    

    【讨论】:

      猜你喜欢
      • 2017-01-19
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2012-12-06
      • 1970-01-01
      • 2012-05-19
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多