【问题标题】:htaccess redirect for HTTPSHTTPS 的 htaccess 重定向
【发布时间】:2014-03-05 02:13:24
【问题描述】:

在尝试将 http 重定向到 https 时,我的 htaccess 文件有点问题。我查看了堆栈上的其他问题,并尝试实施它们以查看它是否可以解决我的问题,但到目前为止还没有任何效果

我正在尝试使用 htaccess 进行重定向,如果它的 http:// 则重定向到 https://

这是我正在尝试修改的原始 htaccess 规则以使其与 https 一起使用

# Get rid of www.
RewriteCond %{HTTPS} !=on
RewriteCond %{HTTP_HOST} ^www\.(.+)$ [NC]
RewriteRule ^(.*)$ https://%1/$1 [R=301,L]

#route to index
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ /index.php?/$1 [L]

谁能告诉我我需要做些什么才能让它工作,我所做的每一次尝试似乎都会导致服务器错误

问候

卢克

【问题讨论】:

标签: php apache .htaccess mod-rewrite redirect


【解决方案1】:

您需要在您的条件中添加[OR] 标志:

# Get rid of www.
RewriteCond %{HTTPS} !=on [OR]
RewriteCond %{HTTP_HOST} ^www\.(.+)$ [NC]
RewriteCond %{HTTP_HOST} ^(?:www\.|)(.+)$ [NC]
RewriteRule ^(.*)$ https://%1/$1 [R=301,L]

这使得如果它不是 https 或如果有 www

,你会被重定向

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2017-07-15
    • 1970-01-01
    • 2022-01-11
    • 2018-05-07
    • 2021-11-10
    • 2012-12-23
    相关资源
    最近更新 更多