我服务器用得apache 现在是https的协议,用得是apache的rewrite规则
RewriteCond %{SERVER_PORT} !^443$
RewriteRule ^(.*)?$ https://%{SERVER_NAME}/$1 [L,R=301]
但是因为我这边的业务需求,需要把访问一级域名的请求全部重定向到www下,并且要保持https协议。求大神帮一下忙。
apache如何同时重定向https与www
答案:2 悬赏:80 手机版
解决时间 2021-02-15 10:10
- 提问者网友:黑米和小志
- 2021-02-15 03:09
最佳答案
- 五星知识达人网友:冷風如刀
- 2021-02-15 03:59
.htaccess伪静态重定向
如果需要将域名从gworg.com跳转到www.gworg.com,则可以使用一下代码:
RewriteEngine onRewriteCond %{http_host} ^gworg.com [NC]
RewriteRule ^(.*)$https://www.gworg.com/$1[L,R=301]
强制HTTPS
RewriteEngine On
RewriteCond %{SERVER_PORT} 80
RewriteRule ^(.*)$ https://%{HTTP_HOST}/$1 [R,L]
Apache自动跳转到 HTTPS:https://www.gworg.com/ssl/130.html
如果需要将域名从gworg.com跳转到www.gworg.com,则可以使用一下代码:
RewriteEngine onRewriteCond %{http_host} ^gworg.com [NC]
RewriteRule ^(.*)$https://www.gworg.com/$1[L,R=301]
强制HTTPS
RewriteEngine On
RewriteCond %{SERVER_PORT} 80
RewriteRule ^(.*)$ https://%{HTTP_HOST}/$1 [R,L]
Apache自动跳转到 HTTPS:https://www.gworg.com/ssl/130.html
全部回答
- 1楼网友:零点过十分
- 2021-02-15 04:06
解决方案: cd /etc/apache2/sites-enabled sudo vi 000-default.conf 打开default文件后,在default文件顶端加入: servername 127.0.0.1 重启apache2 (sudo /etc/init.d/apache2 restart)就不会提示上述错误了。
我要举报
如以上问答信息为低俗、色情、不良、暴力、侵权、涉及违法等信息,可以点下面链接进行举报!
大家都在看
推荐资讯