Apache 将网站从http迁移到https,现在是';它坏了

Apache 将网站从http迁移到https,现在是';它坏了,apache,.htaccess,codeigniter,http,https,Apache,.htaccess,Codeigniter,Http,Https,我正在实习,他们让我修复一个网站,在从http迁移到https后,它坏了。 我快疯了,已经好几天没修好了。。。我不知道该怎么办,要求我修复它的系统管理员也不知道。他们进行了其他迁移,没有任何问题 我将代码中的URL从http更改为https 这是他们所做的.htaccess: Options -Indexes Options +FollowSymLinks <IfModule mod_rewrite.c> RewriteEngine On RewriteBase / #Remove

我正在实习,他们让我修复一个网站,在从http迁移到https后,它坏了。 我快疯了,已经好几天没修好了。。。我不知道该怎么办,要求我修复它的系统管理员也不知道。他们进行了其他迁移,没有任何问题

我将代码中的URL从http更改为https

这是他们所做的.htaccess:

Options -Indexes
Options +FollowSymLinks
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /

#Removes access to the system folder by users.
#Additionally this will allow you to create a System.php controller,

RewriteCond %{REQUEST_URI} ^system.*
RewriteRule ^(.*)$ index.php?/$1 [L]

#When your application folder isn't in the system folder

RewriteCond %{REQUEST_URI} ^application.*
RewriteRule ^(.*)$ /index.php?/$1 [L]

  #Checks to see if the user is attempting to access a valid file,
  #such as an image or css document, if this isn't true it sends the
  #request to index.php

  RewriteCond %{REQUEST_FILENAME} !-f
  RewriteCond %{REQUEST_FILENAME} !-d
  RewriteRule ^(.*)$ index.php?/$1 [L]
</IfModule>
<IfModule !mod_rewrite.c>
  ErrorDocument 404 /index.php
</IfModule>
选项-索引
选项+FollowSymLinks
重新启动发动机
重写基/
#删除用户对系统文件夹的访问权限。
#此外,这将允许您创建System.php控制器,
重写COND%{REQUEST_URI}^系统*
重写规则^(.*)$index.php?/$1[L]
#当应用程序文件夹不在系统文件夹中时
重写cond%{REQUEST_URI}^应用程序*
重写规则^(.*)$/index.php?/$1[L]
#检查用户是否试图访问有效文件,
#例如图像或css文档,如果这不是真的,它会发送
#请求index.php
重写cond%{REQUEST_FILENAME}-F
重写cond%{REQUEST_FILENAME}-D
重写规则^(.*)$index.php?/$1[L]
ErrorDocument 404/index.php
这是/etc/apache2/sites available/webagename.conf中的内容

Options -Indexes
Options +FollowSymLinks
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /

#Removes access to the system folder by users.
#Additionally this will allow you to create a System.php controller,

RewriteCond %{REQUEST_URI} ^system.*
RewriteRule ^(.*)$ index.php?/$1 [L]

#When your application folder isn't in the system folder

RewriteCond %{REQUEST_URI} ^application.*
RewriteRule ^(.*)$ /index.php?/$1 [L]

#Checks to see if the user is attempting to access a valid file,
#such as an image or css document, if this isn't true it sends the
#request to index.php

RewriteCond %{REQUEST_FILENAME} !-f
 RewriteCond %{REQUEST_FILENAME} !-d
 RewriteRule ^(.*)$ index.php?/$1 [L]
</IfModule>
<IfModule !mod_rewrite.c>
 ErrorDocument 404 /index.php
</IfModule>
选项-索引
选项+FollowSymLinks
重新启动发动机
重写基/
#删除用户对系统文件夹的访问权限。
#此外,这将允许您创建System.php控制器,
重写COND%{REQUEST_URI}^系统*
重写规则^(.*)$index.php?/$1[L]
#当应用程序文件夹不在系统文件夹中时
重写cond%{REQUEST_URI}^应用程序*
重写规则^(.*)$/index.php?/$1[L]
#检查用户是否试图访问有效文件,
#例如图像或css文档,如果这不是真的,它会发送
#请求index.php
重写cond%{REQUEST_FILENAME}-F
重写cond%{REQUEST_FILENAME}-D
重写规则^(.*)$index.php?/$1[L]
ErrorDocument 404/index.php
这里面有/etc/apache2/sites available/webagename le ssl,conf

他们告诉我他们是这样迁移的: Linux命令行:

  • certbot-apache
  • /etc/apache2/sites available/webpagename.conf并编写了这些行
  • a2ensite webageName.conf
  • systemctl重新加载apache2
  • journalctl-xe

  • 有什么想法吗?您还需要知道什么才能检查问题?该网页是PHP/Codeigniter。

    假设您使用的是CodeIgniter3,如下所示和文档所示:

    您需要通过添加到config/config.php文件来启用挂钩:

    $config['enable_hooks']=TRUE

    然后在config文件夹(即application/config/hooks.php)中创建一个名为hooks.php的新文件,并在其中添加以下代码:

    $hook['post_controller_constructor'][] = array(
        'function' => 'redirect_ssl',
        'filename' => 'ssl.php',
        'filepath' => 'hooks'
    );
    
    现在在应用程序文件夹(即application/hooks)中创建一个名为hooks的新目录,然后在hooks文件夹(即application/hooks/ssl.php)中创建一个名为ssl.php的新文件

    在ssl.php文件中添加以下代码:

    function redirect_ssl() {
        $CI =& get_instance();
        $class = $CI->router->fetch_class();
        $exclude =  array();  // add more controller name to exclude ssl.
        if(!in_array($class,$exclude)) {
            // redirecting to ssl.
            $CI->config->config['base_url'] = str_replace('http://', 'https://', $CI->config->config['base_url']);
            if ($_SERVER['SERVER_PORT'] != 443) redirect($CI->uri->uri_string());
        } else {
            // redirecting with no ssl.
            $CI->config->config['base_url'] = str_replace('https://', 'http://', $CI->config->config['base_url']);
            if ($_SERVER['SERVER_PORT'] == 443) redirect($CI->uri->uri_string());
        }
    }
    
    此外,您还可以在config/config.php中将基本url设置为https:

    $config['base\u url']='https://www.my-site.com/';

    最后,在根文件夹中设置.htaccess文件:

    <IfModule mod_rewrite.c>
        RewriteEngine on
        RewriteCond %{REQUEST_FILENAME} !-f
        RewriteCond %{REQUEST_FILENAME} !-d
        RewriteRule ^(.*)$ index.php?/$1 [L,QSA]
    </IfModule>
    
    
    重新启动发动机
    重写cond%{REQUEST_FILENAME}-F
    重写cond%{REQUEST_FILENAME}-D
    重写规则^(.*)$index.php?/$1[L,QSA]
    

    现在,您可以在.htaccess中逐个添加每个规则以检查您的迁移。

    您说的“断开”是什么意思?我们登录,它返回到同一页面(登录表单),它不会登录,也不会重定向到下一页。