【问题标题】:redirect all url and folders from http to https in htaccess file在 htaccess 文件中将所有 url 和文件夹从 http 重定向到 https
【发布时间】:2010-06-01 19:22:54
【问题描述】:

在我的 htaccess 文件中,域从 http 重定向到 https,但是我的任何 url 和文件夹都不会从 http 重定向到 https。示例:www.example.com/example.html 或 www.example.com/folder/example.html 不会从 http 重定向到 https

htaccess文件将所有url和所有文件夹从http重定向到https的重写规则是什么?

【问题讨论】:

    标签: .htaccess redirect


    【解决方案1】:
    # add trailing slash to directories and force SSL
    RewriteCond %{REQUEST_FILENAME} -d
    RewriteCond %{REQUEST_URI} !(/$) 
    RewriteCond %{SERVER_PORT} 80 
    RewriteRule (.*) https://www.example.com/$1/ [R=301,L]
    
    # And for the files
    RewriteCond %{SERVER_PORT} 80 
    RewriteRule ^(.*)$ https://www.example.com/$1 [R,L]
    

    这就是我们所拥有的

    【讨论】:

    • 这很好用,谢谢。但是,我遇到了一个问题,如果 URL 是 mydomain.com/beta/my-page/,因为它最终会将我重定向到 mydomain.com/my-page,您将如何更改表达式以在这种情况下工作?
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2020-07-23
    • 2012-03-27
    • 1970-01-01
    • 2019-06-25
    • 2011-06-13
    • 1970-01-01
    • 2023-03-19
    相关资源
    最近更新 更多