【问题标题】:.htaccess redirect http to https and redirect main page visitor to another page.htaccess 将 http 重定向到 https 并将主页访问者重定向到另一个页面
【发布时间】:2021-06-13 08:56:28
【问题描述】:

我知道这个问题已经被问过好几次了,但是我检查了很多其他的答案,仍然无法解决我的问题。

假设我的网站是example.com

我想将所有http地址重定向到https,同时将所有example.com访问者重定向到example.com/main

这是我尝试过的:

RewriteEngine On
RewriteRule ^(.*)$ https://www.example.com/main/$1 [R,L]

它有点工作,但有一些问题。 如果我输入www.example.com/mainexample.com/main,它会转到http 站点,而不是https。这是为什么呢?

另外,如果我输入example.com/works/01,它就会变成https://www.example.com/main/works/01。它在其中添加了一个额外的“主”文件夹。

如何解决这个问题?

【问题讨论】:

    标签: .htaccess redirect http-redirect


    【解决方案1】:

    您需要检查请求是否来自http URL 方案,然后将该请求重定向到安全连接

    RewriteEngine On
    RewriteCond %{HTTPS} off
    RewriteRule ^(.*)$ https://www.example.com/main/$1 [R,L]
    

    【讨论】:

    • 我试过你的方法,但是不行。同样的问题仍然存在。
    猜你喜欢
    • 1970-01-01
    • 2013-10-18
    • 1970-01-01
    • 2020-11-25
    • 1970-01-01
    • 1970-01-01
    • 2019-03-16
    • 2013-04-09
    • 2014-08-10
    相关资源
    最近更新 更多