Use .htaccess to redirect HTTP to HTTPs

后端 未结 17 1557
刺人心
刺人心 2020-12-02 05:51

Please, don\'t recommend me the long and very detailed thread with more than 173 upvotes. It didn\'t work for me. I have also tried many others (1, 2, 3, 4). They all give m

相关标签:
17条回答
  • 2020-12-02 06:12

    easyest way to redirect http to https in wordpress it to modify site_url and home from http://example.com to https://example.com. Wordpress will do the redirection. ( that is why you get "too many redirects" error, wordpress is redirecting to http while .htaccess will redirect to https )

    0 讨论(0)
  • 2020-12-02 06:13

    Redirect from http to https://www

    RewriteEngine On
    RewriteCond %{HTTP_HOST} ^example\.com [NC]
    RewriteCond %{SERVER_PORT} 80
    RewriteRule ^(.*)$ https://www.example.com/$1 [R=301,L]
    

    This will work for sure!

    0 讨论(0)
  • 2020-12-02 06:15

    Problem solved!

    Final .htaccess:

    <IfModule mod_rewrite.c>
    RewriteEngine On
    RewriteBase /
    
    RewriteCond %{ENV:HTTPS} !=on
    RewriteRule ^.*$ https://%{SERVER_NAME}%{REQUEST_URI} [R,L]
    
    # BEGIN WordPress
    RewriteRule ^index\.php$ - [L]
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteRule . /index.php [L]
    </IfModule>
    
    0 讨论(0)
  • 2020-12-02 06:15

    Just add or replace this code in your .htaccess file in wordpress

    # BEGIN WordPress
    <IfModule mod_rewrite.c>
    RewriteEngine On
    RewriteBase /
    
    RewriteCond %{HTTPS} !=on
    RewriteRule ^ https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]
    
    RewriteRule ^index\.php$ - [L]
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteRule . /index.php [L]
    </IfModule>
    
    # END WordPress
    
    0 讨论(0)
  • 2020-12-02 06:16

    The above final .htaccess and Test A,B,C,D,E did not work for me. I just used below 2 lines code and it works in my WordPress website:

    RewriteCond %{SERVER_PORT} 80 
    RewriteRule ^(.*)$ https://www.thehotskills.com/$1 [R=301,L]
    

    I'm not sure where I was making the mistake but this page helped me out.

    0 讨论(0)
  • 2020-12-02 06:16

    Just add this code, And it will work like charm:

    <IfModule mod_rewrite.c>
        RewriteEngine On
        RewriteCond %{HTTP_HOST}#%{HTTPS}s ^www\.([^#]+)#(?:off|on(s)) [NC]
        RewriteRule ^ http%2://%1%{REQUEST_URI} [R=301,L]
    </IfModule>
    
    0 讨论(0)
提交回复
热议问题