如何重写此 .htaccess 文件以从 CodeIgniter 中删除索引.php并强制使用 HTTPS?



这是我的.htaccess文件的内容。

我想完成两件事:

  1. 从代码点火器 URL 中删除index.php;
  2. 强制所有连接通过https://

HTTPS 工作正常,但index.php保留在 URL 中。我该如何解决这个问题?

<IfModule mod_rewrite.c>
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php/$1 [L]
</IfModule>
RewriteEngine On
RewriteCond %{HTTPS} !=on
RewriteRule ^ https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]

试试这个,

RewriteEngine On
RewriteCond %{HTTPS} !=on
RewriteRule ^ https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php/$1 [L]
</IfModule>

这是CodeIgniter的工作代码,希望这会有所帮助

<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteCond %{HTTP_HOST} !^www.
RewriteRule ^(.*)$ https://www.%{HTTP_HOST}%{REQUEST_URI} [L,R=301]
RewriteCond %{HTTPS} off
RewriteRule ^(.*)$ https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]   
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ /index.php/$1 [L]
</IfModule>

同样从应用程序配置文件夹中的config.php您必须删除索引.php并将其设置为空白

$config['index_page'] = '';

在更改 .htaccess 文件后,检查是否要从基本 URL 中删除 index.php。

最新更新