1

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]
  • can you show us how you coded your redirection? – Kaddath Aug 23 '17 at 10:48
  • @Kaddath I updated my question. – Prabhu Khanna Mahadevan Aug 23 '17 at 10:57
  • You need to include `[OR]` on your first condition in the code that gives you a 503. So `RewriteCond %{HTTPS} off [OR]` – Joe Aug 23 '17 at 10:59
  • @Lag Can you please expand your explanation. – Prabhu Khanna Mahadevan Aug 23 '17 at 11:04
  • Why not use a plugin such as [WP Force SSL](https://wordpress.org/plugins/wp-force-ssl/) – Michael Doye Aug 23 '17 at 12:48
  • Where have you placed this code? Any mod_rewrite directives after the WP front controller is not going to work as intended. When you say "the below code gives me 503", have you also _removed_ the code above, immediately below the WP front controller? Otherwise you will certainly get an error. (But a 503 is unusual here.) – DocRoot Aug 23 '17 at 14:59
  • Please check [http to https redirect solved](https://stackoverflow.com/questions/32049820/use-htaccess-to-redirect-http-to-https/50563575#50563575) this . Its already solved. Thanks – Zihadul Islam May 28 '18 at 10:00

3 Answers3

0

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.

Joe
  • 4,877
  • 5
  • 30
  • 51
0

You need to update wordpress database. Try update wp_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');

 

vadim_hr
  • 533
  • 5
  • 11
0

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>
Pawan Thakur
  • 591
  • 8
  • 19