【问题标题】:Removing index.php in codeigniter -htaccess删除 codeigniter -htaccess 中的 index.php
【发布时间】:2015-03-09 21:25:49
【问题描述】:

过去 4 天我试图从 url 中删除 index.php,但没有成功。

http://domainName.com/CI/index.php/controller-name/function/parameter

CI 是 godaddy 中托管的文件夹。

/
.htaccess
CI

谷歌搜索后,我尝试了以下代码,但只得到一个空白页或错误:500,而且我也不明白其中的逻辑。请有人帮我找出我哪里出错了。

RewriteEngine on
RewriteCond $1 !^(index\.php|[Javascript / CSS / Image root Folder name(s)]|robots\.txt)
RewriteRule ^(.*)$ /index.php/$1 [L]

第二个

RewriteEngine on
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteRule .* index.php/$0 [PT,L] 

我还改了行,CI/application/config/config.php

$config['index_page'] = '';

$config['uri_protocol'] = “REQUEST_URI”

【问题讨论】:

标签: php codeigniter mod-rewrite


【解决方案1】:

这应该可以工作

RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(.*)$ CI/index.php/$1 [L]

【讨论】:

  • 在您的示例中,您没有使用 RewriteBase 将其设置为 CI 文件夹,因为您的应用程序位于该文件夹中。这是动态设置 RewriteBase 的示例。它可能有用。 stackoverflow.com/questions/21062290/…
  • 即使添加 RewriteBase/ CI .. 也不行,任何其他解决方案。
【解决方案2】:

试一试它的工作方式意味着回复我

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

【讨论】:

  • 只需将其保存在您的 ht 访问文件中并尝试
  • 感谢您的回答,但它不起作用..没有指定输入文件。
【解决方案3】:

按照以下步骤操作:

  1. 像这样更改配置文件:

    $config['index_page'] = '';

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

  2. 使用以下 .htaccess:

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

注意:.htaccess 因服务器而异。某些服务器(例如:Godaddy)需要使用以下 .htaccess:

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

see here

在base_url中使用如下代码:

$config['base_url'] = 'http' . ((isset($_SERVER['HTTPS']) && $_SERVER['HTTPS'] == 'on') ? 's' : '').'://'.$_SERVER['HTTP_HOST'].str_replace('//','/',dirname($_SERVER['SCRIPT_NAME']).'/');

【讨论】:

  • 在 apache.conf 中更改 allow ovveride 后,它在 localhost 中工作正常。在 godaddy 服务器中仍然没有解决问题,它显示“没有指定输入文件。”.. 放置你的 htaccess 代码时,url 域名.com/CI/index.php/controller-name/function/parameter 更改为 domainName.com/?/controller-name/function/parameter...任何帮助.!!
  • godaddy 需要使用最后一个 .htaccess。这是一个特例。
  • 我需要在你上面提到的htaccess代码中包含文件夹名称ci吗
  • 不,您不需要包含任何目录名称。它应该可以完美运行。
  • 未指定输入文件 :-( ... 但在 localhost 中工作正常
猜你喜欢
  • 2019-04-06
  • 1970-01-01
  • 2016-05-13
  • 2012-08-15
  • 2023-03-16
  • 2013-03-07
  • 1970-01-01
  • 2014-11-25
  • 2018-09-17
相关资源
最近更新 更多