[英]how to redirect http urls to https url?
When I enter the url it will redirect to http://www.xyz.in , but if I edit it to https://www.xyz.in , the SSL certificate starts working. When I enter the url it will redirect to http://www.xyz.in , but if I edit it to https://www.xyz.in , the SSL certificate starts working.
The problem is how to redirect to https://www.xyz.in when the user enters xyz.in问题是当用户输入 xyz.in 时如何重定向到https://www.xyz.in
Config file:配置文件:
$root = (isset($_SERVER['HTTPS']) ? "https://" : "http://") . $_SERVER['HTTP_HOST'];
$root .= str_replace(basename($_SERVER['SCRIPT_NAME']), '', $_SERVER['SCRIPT_NAME']);
$config['base_url'] = $root;
.htaccess file: .htaccess 文件:
RewriteEngine on
RewriteCond %{HTTPS} off
RewriteCond %{HTTP_HOST} (www\.)?xyx.in
RewriteRule (.*) https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]
I have tried changing RewriteCond %{HTTPS} off
to on
, but it always redirects to http://xyz.in .我尝试将
RewriteCond %{HTTPS} off
更改为on
,但它总是重定向到http://xyz.in 。
RewriteEngine On
RewriteCond %{HTTPS} !on
RewriteRule ^ https://%{HTTP_HOST}%{REQUEST_URI}
I think changing (.*)
to ^
should work out.我认为将
(.*)
更改为^
应该可以解决。 Let me know if it doesn't.如果没有,请告诉我。 Also, make sure mod_rewrite is enabled.
另外,确保 mod_rewrite 已启用。 Clear your browser's cache and try this.
清除浏览器的缓存并尝试此操作。
RewriteCond %{SERVER_PORT} 80
RewriteCond %{HTTP_HOST} ^(www\.)?xyz\.in
RewriteRule ^(.*)$ https://www.xyz.in/$1 [R=301,L]
Try this out.试试这个。 It should work.
它应该工作。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.