php - wordpress http to https redirect not working
Get the solution ↓↓↓I am trying to redirect my wordpress site from http to https. My wordpress site is on EC2 Instance and I followed this link for link for redirection
I am able to see the https working, but however the default redirection from http to https is not happening. Like if I go to http://testwordpress.com it should get redirected to https://testwordpress.com
I followed most of the answers from this link, but nothing seemed to be working for me
# 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>
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteCond %{SERVER_PORT} 443
RewriteRule ^(.*)$ https://testwordpress.com/$1 [R,L]
</IfModule>
# END WordPress
The below code gives me 503 error code
RewriteEngine On
RewriteCond %{HTTPS} off
RewriteCond %{HTTPS_HOST} !^testwordpress.com$ [NC]
RewriteRule ^(.*)$ https://testwordpress.com/$1 [L,R=301]
Answer
Solution:
To force HTTPs using.htaccess
all you need to use is:
RewriteEngine On
RewriteCond %{HTTPS} !=on
RewriteRule ^(.*)$ https://%{HTTP_HOST}%{REQUEST_URI} [R=301,L]
Place this at the top of your.htaccess
file and make sure you clear your cache before testing this.
Answer
Solution:
You need to update wordpress database. Try updatewp_options
first.
UPDATE wp_options SET option_value = replace(option_value, 'http://www.oldurl', 'http://www.newurl') WHERE option_name = 'home' OR option_name = 'siteurl';
UPDATE wp_posts SET guid = replace(guid, 'http://www.oldurl','http://www.newurl'); UPDATE wp_posts SET post_content = replace(post_content, 'http://www.oldurl', 'http://www.newurl');
UPDATE wp_postmeta SET meta_value = replace(meta_value,'http://www.oldurl','http://www.newurl');
В
Answer
Solution:
Permanent URL redirect
// Add following code in htaccess
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
Redirect 301 / https://testwordpress.com
</IfModule>
Make sure you have entered https in backend:
WordPress Address (URL)
Site Address (URL)
OR
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
# Rewrite HTTP to HTTPS
RewriteCond %{HTTPS} !=on
RewriteRule ^(.*) https://%{testwordpress.com}/$1 [R,L]
</IfModule>
Share solution ↓
Additional Information:
Link To Answer People are also looking for solutions of the problem: closed without sending a request; it was probably just an unused speculative preconnection
Didn't find the answer?
Our community is visited by hundreds of web development professionals every day. Ask your question and get a quick answer for free.
Similar questions
Find the answer in similar questions on our website.
Write quick answer
Do you know the answer to this question? Write a quick response to it. With your help, we will make our community stronger.