[英]not able to redirect HTTP to HTTPS using rewrite in htaccess
I have tried url redirection of HTTP to HTTPS on my website by using several different solutions in .htaccess and none have worked. 我已经尝试使用.htaccess中的几个不同的解决方案在我的网站上将HTTP重定向到HTTPS,但没有一个有效。 Well, actually it does work if I type in directly:
嗯,实际上如果我直接输入它确实有效:
(only for example) http://mywebsite.com (仅举例) http://mywebsite.com
into the browser address bar....but if I try to redirect the url any other way, it won't work. 进入浏览器地址栏....但如果我尝试以任何其他方式重定向该URL,它将无法正常工作。 If I try the link to my page listed on Google http://mywebsite.com/ it will not redirect to https://www.mywebsite.com .
如果我尝试链接到我在http://mywebsite.com/上列出的页面,它将不会重定向到https://www.mywebsite.com 。 I need it to redirect from HTTP to HTTPS if someone clicks the link to my page from a search engine.
如果有人从搜索引擎点击指向我页面的链接,我需要它从HTTP重定向到HTTPS。
So far I have tried: 到目前为止,我尝试过:
RewriteEngine On
RewriteCond %{SERVER_PORT} 80
RewriteRule ^(.*)$ https://www.example.com/$1 [R,L]
then I tried... 然后我试了......
Options +FollowSymLinks
RewriteEngine on
RewriteCond %{HTTP_HOST} ^example.com [NC]
RewriteRule ^(.*)$ https://www.example.com/$1 [R=301,L]
and then I tried... 然后我试了......
RewriteCond %{SERVER_PORT} !443
RewriteRule ^(.*)$ https://www.%{HTTP_HOST}/$1 [R,L]
None worked. 没有用。 What else should I try?
我还应该尝试什么? (this website is being hosted on a web hosting service site that has uses an apache web server).
(此网站托管在使用apache Web服务器的Web托管服务站点上)。 Also, I have an SSL certificate for the page, if that makes any difference.
此外,我有一个页面的SSL证书,如果这有任何区别。
Enable mod_rewrite and .htaccess through httpd.conf
and then put this code in your .htaccess
under DOCUMENT_ROOT
directory: 通过
httpd.conf
启用mod_rewrite和.htaccess,然后将此代码放在DOCUMENT_ROOT
目录下的.htaccess
:
Options +FollowSymLinks -MultiViews
# Turn mod_rewrite on
RewriteEngine On
RewriteBase /
RewriteCond %{HTTPS} off
RewriteRule ^ https://%{HTTP_HOST}%{REQUEST_URI} [R=301,L]
Tip: Clear your browser cache or use a different browser to test. 提示:清除浏览器缓存或使用其他浏览器进行测试。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.