将网站从http重定向到https [英] Redirect a website from http to https
问题描述
我目前正在运行一个以struts编写的网站.我正在使用Apache Web服务器并使用AJP进行代理将我的Web应用程序传递到Apache tomcat服务器.
I am currently running a website written in struts. I am using Apache web server and using AJP to ProxyPass my web application to Apache tomcat server.
我的服务器是Amazon托管的Ubuntu服务器.我能够使用http成功运行我的Web应用程序.
My server is Ubuntu server hosted in Amazon. I was able to run my web application successfully using http.
现在,我正计划为上述Web应用程序实现SSL.我已经完成所有SSL实施步骤,现在可以使用https (即https://{MY_APPLICATION_URL}
Now I am planning to implement SSL for the above web application. I have completed all the SSL implementation steps and now I can access my web application successfully using https that is, https://{MY_APPLICATION_URL}
现在问题出在:当用户输入我的应用程序URL(例如http://{MY_APPLICATION_URL}或{MY_APPLICATION_URL})时,我需要重定向并使其仅使用https://{MY_APPLICATION_URL}. http访问不能在那里.
Now the issue is with: when user enter my application URL like http://{MY_APPLICATION_URL} or {MY_APPLICATION_URL}, I need to redirect and make them to only use https://{MY_APPLICATION_URL}. http access must not be there.
我找到了以下链接: http://www.sslshopper. com/apache-redirect-http-to-https.html 和已安装重写模块在apache服务器中(通过webmin).然后在我的应用程序的虚拟主机中添加以下几行(编辑指令).
I found the following link: http://www.sslshopper.com/apache-redirect-http-to-https.html and installed rewrite module in apache server (through webmin). Then added the following lines in my application's virtual host (Edit directives).
RewriteEngine On
RewriteCond %{HTTPS} off
RewriteRule (.*) https://%{HTTP_HOST}%{REQUEST_URI}
即使在上述重定向之后,当用户输入http://{MY_APPLICATION_URL}或{MY_APPLICATION_URL}时,也会显示我的apache服务器的默认欢迎页面.但是,当我输入https://{MY_APPLICATION_URL}时,我能够成功访问我的Web应用程序.
Even after above redirecting, when user enters http://{MY_APPLICATION_URL} or {MY_APPLICATION_URL} it displays my apache server's default welcome page. However when I type https://{MY_APPLICATION_URL}, I was able to access my web application successfully.
任何人都可以指导我做错了什么地方.
Can anyone please guide me where I am doing wrong.
谢谢.
推荐答案
此解决方案对我有帮助.
This solution helped me.
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteCond %{SERVER_PORT} 80
RewriteRule ^(.*)$ https://domain.name/$1 [R,L]
</IfModule>
我希望它也会对您有所帮助.
I hope it'll be helpfull for you too.
这篇关于将网站从http重定向到https的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!