【问题标题】:codeigniter work only with index.php in the urlcodeigniter 仅适用于 url 中的 index.php
【发布时间】:2014-07-07 06:00:21
【问题描述】:

我有一个带有路由的 CI 安装

$route['signin']="auth/login";
$route['logout']="auth/logout";
$route['signup']="auth/register";

我的 ci 安装位于 www.domain.com/app/

当我转到这个 url 时,它会路由到 www.domain.com/app/signin/ 但它会显示

The requested URL /www.domain.com/app/signin was not found on this server.

但是当我手动插入 index.php 时

www.domain.com/app/index.php/signin

然后它会打开。

可能是什么问题?我已经配置了 htaccess。

这个 ci 安装在另一台服务器上,我将它转移到这个新服务器上。我将基本 url 保留为空白。

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 代码在哪里
  • 有分步解决方案:goo.gl/3jfW8f
  • @user3637105 查看答案
  • 有时取决于您的托管服务器。能否请您提及您的托管服务器提供商名称。
  • 那么你的 .htaccess 看起来不错。可能你还有其他问题。

标签: php .htaccess codeigniter


【解决方案1】:

这个 ci 安装在另一个服务器上,我把它转移到这个新服务器上。

基于它在另一台服务器上工作,新服务器似乎没有配置AllowOverride Apache 设置来启用 htaccess,这意味着您的 htaccess 被禁用或忽略。或者新服务器是一个非 Apache Web 服务器,它根本不识别 htaccess。

【讨论】:

  • 我的是 apache.SO 如何启用 htaccess ?任何?
  • 点击答案中的AllowOverride链接了解如何启用它。要为 htaccess 提供完全访问权限,请在 httpd.conf 文件中使用 AllowOverride All(在 <Directory> 部分中)。
【解决方案2】:

你需要更新 config.php 到这个

/*
|--------------------------------------------------------------------------
| Base Site URL
|--------------------------------------------------------------------------
|
| URL to your CodeIgniter root. Typically this will be your base URL,
| WITH a trailing slash:
|
|   http://example.com/
|
| If this is not set then CodeIgniter will guess the protocol, domain and
| path to your installation.
|
*/
$config['base_url'] = 'http://domain.com/app/';

/*
|--------------------------------------------------------------------------
| Index File
|--------------------------------------------------------------------------
|
| Typically this will be your index.php file, unless you've renamed it to
| something else. If you are using mod_rewrite to remove the page set this
| variable so that it is blank.
|
*/
$config['index_page'] = ''; // Remove index.php

现在.htaccess

RewriteEngine on

# RewriteBase /
RewriteBase /app/

RewriteCond $1 !^(index\.php|images|robots\.txt)
RewriteRule ^(.*)$ /index.php/$1 [L]

【讨论】:

    【解决方案3】:

    试试这个:

    RewriteEngine on
    RewriteBase/app/
    
    # Add www in the start of URL if user leave
    #RewriteCond %{HTTP_HOST} !^www\.
    #RewriteRule ^(.*)$ http://www.%{HTTP_HOST}/$1 [R=301,L]
    
    # Prevent CI index.php
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteRule .* index.php/$0 [PT,L]
    
    # Prevent user access to the CI system folder.
    RewriteCond %{REQUEST_URI} ^system.*
    RewriteRule ^(.*)$ /index.php?/$1 [L]
    
    # Prevent user access to the CI application folder
    RewriteCond %{REQUEST_URI} ^application.*
    RewriteRule ^(.*)$ /index.php?/$1 [L]
    

    设置RewriteBase 这样RewriteBase/app/

    【讨论】:

      猜你喜欢
      • 2013-12-12
      • 1970-01-01
      • 2017-06-21
      • 2013-11-03
      • 2013-10-12
      • 1970-01-01
      • 1970-01-01
      • 2014-07-20
      • 1970-01-01
      相关资源
      最近更新 更多