如何使用 .htaccess 将 https:// 重定向到 https://www

问题描述 投票:0回答:1

我需要使用 .htaccess 将 https://、http:// 重定向到 https://www。

这是我的基本网址https://www.mysite.co.bw/,我需要重定向https://mysite.co.bw/http://mysite.co.bw/使用 .htaccess 到基本 URL

我已经在 CodeIgniter 3 中完成了这个网站。

这就是我到目前为止所做的。

RewriteEngine On
RewriteCond %{HTTP_HOST} ^mysite\.co\.bw$ [OR]
RewriteCond %{HTTPS} off
RewriteRule ^(.*)$ https://www.mysite.co.bw/$1 [R=301,L]


# Your existing CodeIgniter rules
RewriteCond $1 !^(index\.php|assets|images|js|css|uploads|favicon.png)
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ ./index.php/$1 [L]

但是上面的代码对我不起作用。

php .htaccess codeigniter url
1个回答
0
投票

你可以使用这样的东西:

RewriteEngine On
RewriteBase /

RewriteCond %{HTTPS} !=on
RewriteRule ^ https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]

RewriteCond %{HTTP_HOST} ^www\.(.*)$ [NC]
RewriteRule ^(.*)$ https://%1%{REQUEST_URI} [R=301,QSA,NC,L]
© www.soinside.com 2019 - 2024. All rights reserved.