简体   繁体   English

使用htaccess将所有流量重定向到裸域SSL

[英]Redirect all traffic to bare domain SSL using htaccess

I'm trying to redirect all traffic through HTTPS and here's my htaccess file: 我正在尝试通过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>

Currently here's what's going on, 目前正在发生的事情,

If the user types in www.domain.com it redirects to: https://domain.com which is good. 如果用户在www.domain.com中输入,则会重定向到: https//domain.com ,这很好。 I would like help in configuring the file so that if the user also types in domain.com they get redirected to https://domain.com 我想帮助配置文件,以便如果用户也输入domain.com,他们会被重定向到https://domain.com

It would be as simple as updating your pattern: 它就像更新你的模式一样简单:

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM