index.php没有删除https CodeIgniter

Dee*_*rma 8 php .htaccess codeigniter

我使用https时不会删除index.php,但它适用于http.我需要做的是我的网站正常工作,例如它适用于httphttps.任何遇到同样问题的人都会帮我解决这个问题.

例如:在http

  1. http://xyz.mydomain.com/users/login //工作正常
  2. http://xyz.mydomain.com/index.php/users/login //工作正常

在https

1)https://xyz.mydomain.com/users/login //未找到404页
2)https://xyz.mydomain.com/index.php/users/login //工作正常

我的htaccess代码

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

config.php 我的基本网址设置为

$root=(isset($_SERVER['HTTPS']) ? "https://" : "http://").$_SERVER['HTTP_HOST'];
$root.= str_replace(basename($_SERVER['SCRIPT_NAME']), '', $_SERVER['SCRIPT_NAME']);
$config['base_url'] = $root;
Run Code Online (Sandbox Code Playgroud)

Suj*_*mar 1

看来您的主机文件有问题。如果您使用 apache,请更改您的主机文件,例如;

<VirtualHost *:443>
   ServerAdmin admin@example.com
   DocumentRoot /path
   ServerName xyz.mydomain.com
   ServerAlias www.xyz.mydomain.com

   SSLEngine On
   SSLOptions +StrictRequire
   SSLCertificateFile /path to ssl file/mydomain.crt
   SSLCertificateKeyFile /path to ssl file/mydomain.key
   SSLProtocol TLSv1
    <Directory "/path">
        Require all granted
        Options -FollowSymLinks -Includes -ExecCGI -Indexes
        AllowOverride All
        Order allow,deny
        Allow from all
    </Directory>
    RewriteEngine On
</VirtualHost>
Run Code Online (Sandbox Code Playgroud)

现在更改您的 htaccess 文件,如下所示:

<IfModule mod_rewrite.c>
   Options +FollowSymLinks
   RewriteEngine On
   RewriteCond %{SERVER_PORT} 80
   RewriteRule ^(.*)$ https://xyz.mydomain.com/$1 [R=301,L]

   RewriteCond %{REQUEST_FILENAME} !-f
   RewriteCond %{REQUEST_FILENAME} !-d
   RewriteRule ^(.*)$ index.php/$1 [L]
</IfModule>
Run Code Online (Sandbox Code Playgroud)

快乐编码:)