将www.example.com和https://www.example.com重定向到https://example.com

时间:2019-07-25 05:12:11

标签: .htaccess

我有一个名为https://example.com

的URL

我想将请求从www.example.com和https://www.example.com重定向到.htaccess文件中的https://example.com

请大家帮帮我吗?

谢谢!

1 个答案:

答案 0 :(得分:0)

在.htaccess文件顶部检查此规则

<IfModule mod_rewrite.c>
    RewriteEngine On

    # Redirect all www requests to https non www
    RewriteCond %{HTTP_HOST} ^www\. [NC]
    RewriteRule (.*) https://example.com/$1 [R=301,L]

    # Redirect all other http requests (ex. http://example.com) to https non www
    RewriteCond %{HTTPS} off
    RewriteRule (.*) https://example.com/$1 [R=301,L]
</IfModule>