【问题标题】:htaccess redirect http to https for subdirectoryhtaccess 将 http 重定向到 https 的子目录
【发布时间】:2014-04-22 08:01:49
【问题描述】:

我使用此重定向是因为我的网站位于子文件夹 (www.domain.com/subfolder/) 中

所以如果有人进入网站,它会像这样加载:http://domain.com

我需要在 .htaccess 中添加或更改什么,以便它自动重定向到 https://domain.com,计算该网站位于 domain.com/subfolder

我尝试了各种重定向代码,但都没有成功。如果有人好心指出我正确的方向或给我一个提示。

感谢您的帮助。

RewriteEngine on
RewriteCond %{HTTP_HOST} ^(www.)?domain.com$
RewriteCond %{REQUEST_URI} !^/subfolder/
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ /subfolder/$1
RewriteCond %{HTTP_HOST} ^(www.)?domain.com$
RewriteRule ^(/)?$ subfolder/index.html [L]

【问题讨论】:

    标签: .htaccess redirect ssl


    【解决方案1】:

    将此代码放入您的DOCUMENT_ROOT/.htaccess 文件中:

    RewriteEngine On
    RewriteBase /
    
    RewriteCond %{HTTPS} off
    RewriteRule ^ https://{HTTP_HOST}%{REQUEST_URI} [R=301,L,NE]
    
    RewriteRule !^subfolder/ subfolder%{REQUEST_URI} [L,NC]
    

    【讨论】:

    • 你得到的是 404 页面吗?
    猜你喜欢
    • 1970-01-01
    • 2016-10-23
    • 2012-11-02
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-10-08
    相关资源
    最近更新 更多