Reputation: 6560
I've been doing some 301 redirects as Google has cached/save old links. So I set up my 301 redirects:
Redirect 301 /old/url/ /index.php/old/url
however I noticed the url weren't https://
they were www.example.com/index.php/old/url
I did some searching online for enforce https
via .htaccess
but everything I try causes whole site to come up with error
Page isn't Redirecting Properly
Here is my .htaccess (minus the 301 redirects):
# BEGIN WordPress
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
</IfModule>
# END WordPress
# force https
# RewriteCond %{HTTPS} !=on
# RewriteRule ^ https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]
# RewriteCond %{HTTPS} !=on
# RewriteRule ^.*$ https://%{SERVER_NAME}%{REQUEST_URI} [R,L]
# ensure https
# RewriteCond %{HTTP:X-Forwarded-Proto} !https
# RewriteCond %{HTTPS} off
# RewriteRule ^ https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]
# RewriteCond %{HTTPS} off
# RewriteRule ^(.*)$ https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]
As you can see I've tried a few different ways of achieving this, but all of them product the above error (they're not all uncommented at the same time).
My site is all https, except for this old links Google has when you search for them, but the redirects don't include the https part, and if I try to do a full url (e.g. Redirect 301 /old/url/ https://www.example.com/old/url
) then it still doesn't work.
How do I enforce https for www.example urls without breaking the site?
Thanks
Upvotes: 0
Views: 58
Reputation: 807
First, you need to visit Settings » General page. From here you need to update your WordPress and site URL address fields by replacing http with https.
you need to set up WordPress redirects from HTTP to HTTPS by adding the following code to your .htaccess file.
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteCond %{HTTPS} off
RewriteRule ^(.*)$ https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]
</IfModule>
If you want to force SSL and HTTPS on your WordPress admin area or login pages, then you need to configure SSL in the wp-config.php file. Add the following code above the “That’s all, stop editing!” line in your wp-config.php file:
define('FORCE_SSL_ADMIN', true);
Upvotes: 1