当前位置: 首页 > 后端技术 > PHP

Apache2.4服务配置http自动跳转https

时间:2023-03-29 14:49:24 PHP

部署的php项目想要http自动跳转https,前提是你需要能够用https访问php页面,如何配置https需要获取相关证书文件(key,crt)),然后需要修改httpd.conf和httpd-ssl.conf中的相关配置,这里不再赘述。下面的内容只有在HTTPS能够独立访问自己的页面成功后才能实现。首先在httpd.conf中配置如下:打开Apache重写模块(去掉#):LoadModulerewrite_modulemodules/mod_rewrite.so然后修改Directory中的内容,注意修改配置项DocumentRoot"E:/wsp/www"OptionsIndexesFollowSymLinksAllowOverrideAllRewriteEngineonRewriteCond%{SERVER_PORT}!^443$RewriteRule^(.*)?$https://%{SERVER_NAME}%{REQUEST_URI}[L,R]要求allgranted在bin目录下打开cmd,运行httpd-t如果语法正确,重启Apache就成功了