Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
260 views
in Technique[技术] by (71.8m points)

.htaccess - Not Directing Http/www traffic to HTTPS

so I have installed ssl certificate on my server, so if search using https://www.domain.info its secure connection. but if i search using www.domain.info or http://www.domain.info it doesnt redirect to https for a secure connection.

this is my current htaccess content


RewriteEngine On

RewriteCond %{HTTPS} off [OR]
RewriteCond %{HTTP_HOST} ^www. [NC]
RewriteCond %{HTTP_HOST} ^(?:www.)?(.+)$ [NC]
RewriteRule ^ https://%1%{REQUEST_URI} [L,NE,R=301]

question from:https://stackoverflow.com/questions/65837973/not-directing-http-www-traffic-to-https

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

Looks like your htaccess file is not enabled mod rewrite rule at present, try un-commenting line LoadModule rewrite_module modules/mod_rewrite.so once. Plus go through article https://phoenixnap.com/kb/how-to-set-up-enable-htaccess-apache for understanding on how to enable htaccess file.

Also change your rules to following.

RewriteEngine On

RewriteCond %{HTTPS} off
RewriteCond %{HTTP_HOST} ^(?:www.)?(.*)$ [NC]
RewriteRule ^ https://%1%{REQUEST_URI} [L,NE,R=301]

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

2.1m questions

2.1m answers

60 comments

57.0k users

...