【问题标题】:Redirect all traffic to bare domain SSL using htaccess使用 htaccess 将所有流量重定向到裸域 SSL
【发布时间】:2016-09-23 12:35:07
【问题描述】:

我正在尝试通过 HTTPS 重定向所有流量,这是我的 htaccess 文件:

<IfModule mod_rewrite.c>
Options +FollowSymLinks -Indexes
    RewriteEngine on
    RewriteCond %{HTTPS} off
    RewriteCond %{HTTP_HOST} ^www\.(.+)$ [NC]
    RewriteRule ^ https://%1%{REQUEST_URI} [R=301,L]
    RewriteBase /

    RedirectMatch 301 /index.php/(.*)$ /$1

    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteRule ^(.*)$ index.php?/$1 [L]
</IfModule>
<IfModule !mod_rewrite.c>
    ErrorDocument 404 index.php
</IfModule>

目前情况如下,

如果用户键入 www.domain.com,它会重定向到:https://domain.com,这很好。我需要帮助配置文件,以便如果用户还输入 domain.com 他们会被重定向到https://domain.com

【问题讨论】:

    标签: apache .htaccess mod-rewrite ssl url-redirection


    【解决方案1】:

    这就像更新你的模式一样简单:

    RewriteEngine on
    RewriteCond %{HTTPS} off
    RewriteCond %{HTTP_HOST} ^(?:www\.)?(.+)$ [NC]
    RewriteRule ^ https://%1%{REQUEST_URI} [R=301,L]
    

    【讨论】:

    • 您说得对。当你回答时,我更新了模式,它确实有效。非常感谢。
    猜你喜欢
    • 2014-01-11
    • 1970-01-01
    • 2014-08-23
    • 2015-03-13
    • 2015-04-24
    • 1970-01-01
    • 2012-05-05
    • 1970-01-01
    • 2010-10-07
    相关资源
    最近更新 更多