【问题标题】:Codeigniter 2.1.4 installation in sub directoryCodeigniter 2.1.4 安装在子目录
【发布时间】:2014-02-23 12:23:00
【问题描述】:

我在根目录下成功安装了很多次CI,但现在我被强制安装CI在https://mydomain.com/mvc

存在一个控制器“登录”和一个动作“索引”

.htaccess 文件如下所示:

Options +FollowSymLinks  
RewriteEngine on  
RewriteBase /mvc  
RewriteRule ^(.*)$ index.php?/$1 [L]  

在 config/config.php 中

$config['base_url'] = 'https://mydomain.com/mvc/';  
$config['index_page'] = '';  

我的路线如下:

$route['default_controller'] = "login";  
$route['login'] = "login/index";  
$route['404_override'] = '';  

mod_rewrite 已启用
https://mydomain.com/mvc 给出 404
https://mydomain.com/mvc/login 给出 404
我错过了什么?

【问题讨论】:

    标签: .htaccess codeigniter routing subdirectory


    【解决方案1】:

    您的主机是什么?如果是 hostgator,您需要添加您的用户。

    试试这个

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

    如果您的主机是 hostgator,您需要添加您的用户名,例如

    RewriteEngine On
    RewriteBase /~<name_user>/%{HTTP_HOST} <or> <your folder>
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteRule ^(.*)$ /~<name_user>/%{HTTP_HOST} <or> <your folder>/index.php/$1 [L]
    

    【讨论】:

    • 托管公司是softlayer.com
    • 我试过这个,同样的问题,404。
    • 尝试检查您的 mod_rewrite 是否处于活动状态,您可以阅读如何:stackoverflow.com/questions/9021425/…
    • 检查您的 config.php? $config['base_url'] = 'mydomain.com'; $config['index_page'] = ''; $config['uri_protocol'] = 'REQUEST_URI';
    【解决方案2】:

    试试这个

    RewriteEngine on
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteRule ^(.*)$ /mvc/index.php?/$1 [L]
    

    【讨论】:

    • 我试过这个,同样的问题,404。
    【解决方案3】:

    试试这个 设置子目录的默认基本 url

    $config['base_url'] = "http://www.example.com/subdir/"

    打开 config.php 并进行以下替换

    $config['index_page'] = "index.php"
    

    到

    $config['index_page'] = ""
    

    在某些情况下,uri_protocol 的默认设置无法正常工作。所以你只需要替换它

    $config['uri_protocol'] ="AUTO"
    

    通过

    $config['uri_protocol'] = "REQUEST_URI"
    

    .htaccess

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

    此代码运行所有子目录。希望这个能对您有所帮助!。

    【讨论】:

      【解决方案4】:

      我遇到了同样的问题,我可以通过更新 /etc/apache2/sites-enabled/000-default.conf 文件来解决它

      试试这个。

      mvc/.htaccess

      <IfModule mod_rewrite.c>
        RewriteEngine On
        RewriteCond %{REQUEST_FILENAME} !-f
        RewriteCond %{REQUEST_FILENAME} !-d
        RewriteRule ^(.*)$ index.php?/$1 [L]
      </IfModule>
      

      mvc/application/config/config.php

      $config['base_url'] = 'https://yourdomain.com/mvc/';
      

      /etc/apache2/sites-enabled/000-default.conf

      <VirtualHost *:80>
      
          .... 
      
          <Directory /your/root/directory> # /var/www/html
              Options Indexes FollowSymLinks MultiViews
              AllowOverride All
              Require all granted
          </Directory>
      
      </VirtualHost>
      

      【讨论】:

        猜你喜欢
        • 2011-01-31
        • 2013-03-28
        • 2018-06-26
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2012-11-02
        • 1970-01-01
        相关资源
        最近更新 更多