.htaccess issue to force SSL

2019-09-09 16:47发布

问题:

I activated SSL on one of my sites (based on wordpress) and want to modify .htaccess to modify content's links to https.
I mean, into https://www.example.com/products.html page is a http://example.com/blah-blah.jpg
i want to change it to https://www.example.com/blah-blah.jpg via .htaccess and i don't have any idea! :|
I installed and activated HTTPS for WordPress plugin but some links not change to https.

回答1:

Mr. Schulman's solution forgets the slash after the domain name, so the user is redirected to https://www.example.comcategory/cat1/cat2/ which is not quite right. I added a slash to his .htaccess entry, and it worked just fine. Consider:

RewriteCond %{HTTPS} off
RewriteRule (.*)  https://example.com/$1 [R]


回答2:

Try putting this in .htaccess:

RewriteCond %{HTTPS} off
RewriteRule (.*)  https://www.example.com$1 [R]

Of course this will require that you have mod_rewrite enabled.