【问题标题】:http to https with full path and queries [apache]带有完整路径和查询的 http 到 https [apache]
【发布时间】:2015-11-23 21:29:35
【问题描述】:

对不起,如果这个问题已经发布但我搜索了两次。

我想将我的 http:// 域重定向到 https:// 并且还 http:// example.com/homehttp:/ /www.example.com/homehttps://example.com/home

我用谷歌搜索,但不明白哪一种是完美的重定向方式。 我使用这个工作,但只有当一个人访问 http,如果有人直接打开 https 而不是收到错误 此页面有太多重定向

.ht访问代码

Options +FollowSymLinks RewriteEngine On RewriteRule ^(.*)

http://www.newdomain.com%{REQUEST_URI} [R=302,NC]

我认为这是旧域到新域,但我不想重定向到另一个域。 将 http 重定向到 https 的域相同。 请解决这个问题

【问题讨论】:

    标签: php apache .htaccess mod-rewrite redirect


    【解决方案1】:

    这是你的答案:

    RewriteEngine On
    RewriteCond %{HTTPS} off
    RewriteRule (.*) https://%{HTTP_HOST}%{REQUEST_URI} [R,L]
    

    或者使用这个:

    RewriteEngine on
    
    RewriteCond     %{SERVER_PORT} ^80$
    RewriteRule     ^(.*)$ https://%{SERVER_NAME}%{REQUEST_URI} [L,R]
    

    端口 80 是 http 并强制为 443 https。

    【讨论】:

    • 当我尝试打开 www.site.com 时出现此错误This webpage has a redirect loop ERR_TOO_MANY_REDIRECTS
    • 你先试试还是第二个?
    • 我都试过了,但现在我自己成功了,我用这个RewriteEngine On RewriteCond %{HTTPS} on
    猜你喜欢
    • 2017-06-11
    • 1970-01-01
    • 2018-04-13
    • 2015-05-24
    • 1970-01-01
    • 1970-01-01
    • 2012-08-04
    • 1970-01-01
    • 2013-05-16
    相关资源
    最近更新 更多