Apache Redirect when the page is SSL

旧巷老猫 提交于 2020-01-06 08:39:38

问题


I have a redirect from http://example.com to http://www.example.com. now i want this redirect to work when the user is in https protocol. meaning to redirect from https://example.com to https://www.example.com. is it possible? if not, how do i redirect https://example.com/page to http://example.com or http://www.example.com

i hope i was clear


回答1:


Redirecting from https://example.com to https://www.example.com works in the same way as redirecting from http://example.com to http://www.example.com, except that you have to put the rewrite rules in your SSL-enabled VirtualHost in addition to your plain HTTP VirtualHost section.

Where you may get a problem is that, for this to work, you need the initial connection to https://example.com to work and be accepted by the browser. For this, you need your certificate to be valid for both www.example.com and example.com. This is typically done by using multiple Subject Alternative Names in your server certificate (you should be able to see this by looking at the details of your certificate). Some CAs issue certificates both with and without the www. prefix.



来源:https://stackoverflow.com/questions/8256037/apache-redirect-when-the-page-is-ssl

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!