What is the best way to implement 301 redirect from http to https?
-
Hi Folks,
I just installed an SSL certificate on my website and I want to redirect all http traffic to https.My question is: What is the best way to do this? and considering that for best SEO the redirects should be 301.
What I’ve tried is:
1. Edit the .htaccess with the following code:# 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 # BEGIN Force http to https RewriteEngine On RewriteCond %{HTTPS} off RewriteRule (.*) https://%{HTTP_HOST}%{REQUEST_URI} [R=301,L] # END Force http to https
I didn’t have much luck, it seemed to work with the homepage, but if somebody typed an url with http it did not redirect to its https counterpart.
2. Edit the .htaccess with the following code:
# 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 # BEGIN Force http to https RewriteEngine On RewriteCond %{SERVER_PORT} 80 RewriteRule ^(.*)$ https://mydomain.com/$1 [R=301,L] # END Force http to https
Again, it seemed to work with the homepage, but if somebody typed an url with http it did not redirect to its https counterpart.
3. Finally I installed the plugin WP Force ssl, but Im not sure if the redirects are done in the right way(301 redirects) for better SEO.
Any thoughts on this? Why does the code in my .htaccess is not working?. How have you managed this redirection for your sites?
any ideas would be appreciated. Thanks.
- The topic ‘What is the best way to implement 301 redirect from http to https?’ is closed to new replies.