简体   繁体   中英

Redirect www.example.com and https://www.example.com into https://example.com

i have a URL called https://example.com

I would like to redirect request from www.example.com and https://www.example.com into https://example.com in .htaccess file.

Could guys please help me?

Thanks!

Check this rule on the top of your .htaccess file

<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>

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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