Title: Redirect from http to https
Last modified: November 6, 2019

---

# Redirect from http to https

 *  [wmchugh](https://wordpress.org/support/users/wmchugh/)
 * (@wmchugh)
 * [6 years, 6 months ago](https://wordpress.org/support/topic/redirect-from-http-to-https-3/)
 * My site is all setup to work https: so I need to redirect all http to https.
 * I’ve searched for .htaccess code to do the job, and everyone seems pretty much
   agreed that the below (although there are variatrions around) will do the job.
   However it is producing the “too many redirects” error.
 * The thing is: without this addition to .htaccess, my home page redirects to https
   but no other page do. With this code, all pages give too many redirects. Using
   wheregoes.com to trace the redirects, without this extra .htacces code there 
   are no redirects on http or https pages (except the home page). If there are 
   no redirects on https pages now, the cause of it must be in the code below. But
   this is what everyone recommends, so I don’t understand. I know little of .htacces
   syntax, unfortunately.
 * Any insights very much appreciated.
 * # BEGIN HTTPS Redirection Plugin
    <IfModule mod_rewrite.c> RewriteEngine On RewriteCond%{
   SERVER_PORT} !^443$ RewriteRule ^(.*)$ [https://%](https://%){HTTP_HOST}%{REQUEST_URI}[
   L,R=301] </IfModule> # END HTTPS Redirection Plugin
 * #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
 * The page I need help with: _[[log in](https://login.wordpress.org/?redirect_to=https%3A%2F%2Fwordpress.org%2Fsupport%2Ftopic%2Fredirect-from-http-to-https-3%2F%3Foutput_format%3Dmd&locale=en_US)
   to see the link]_

Viewing 7 replies - 1 through 7 (of 7 total)

 *  [autotutorial](https://wordpress.org/support/users/autotutorial/)
 * (@autotutorial)
 * [6 years, 6 months ago](https://wordpress.org/support/topic/redirect-from-http-to-https-3/#post-12101099)
 * .htaccess not work for nginx
 *     ```
       server {
           listen 80;
           listen [::]:80;
           server_name linuxize.com www.linuxize.com;
           return 301 https://linuxize.com$request_uri;
       }
       ```
   
 * [https://linuxize.com/post/redirect-http-to-https-in-nginx/](https://linuxize.com/post/redirect-http-to-https-in-nginx/)
   
   Wordpress guide for https, W3 total cache and other [https://wordpress.org/support/article/nginx/](https://wordpress.org/support/article/nginx/)
 *  [catacaustic](https://wordpress.org/support/users/catacaustic/)
 * (@catacaustic)
 * [6 years, 6 months ago](https://wordpress.org/support/topic/redirect-from-http-to-https-3/#post-12101170)
 * Use the [Better Search Replace](https://wordpress.org/plugins/better-search-replace/)
   plugin to change every instance of ‘[http://youriste.com&#8217](http://youriste.com&#8217);
   to ‘[https://yoursite.com&#8217](https://yoursite.com&#8217); in your database.
   It’s by far the quickest and easiest way to do it, and there’sno need for messing
   about with .htaccess or anything else.
 *  [Lukasz](https://wordpress.org/support/users/wpfed/)
 * (@wpfed)
 * [6 years, 6 months ago](https://wordpress.org/support/topic/redirect-from-http-to-https-3/#post-12103533)
 * As mentioned above you’re server is running on NGINX, not APACHE, so you can’t
   use .htaccess
 * I would contact your hosting provider, or log into cpanel where there is a option
   to redirect all http traffic to https.
 * Also add this security header to your functions.php
 *     ```
       /**
        * Adds an HSTS header to the response.
        *
        * @param array $headers The headers to filter.
        * @return array $headers The filtered headers.
        */
       add_filter(
       	'wp_headers',
       	function( $headers ) {
       		$headers['Strict-Transport-Security'] = 'max-age=63072000'; // Or another max-age.
       		return $headers;
       	}
       );
       ```
   
 * “HTTP Strict-Transport-Security response header (often abbreviated as HSTS) lets
   a web site tell browsers that it should only be accessed using HTTPS”
 *  Thread Starter [wmchugh](https://wordpress.org/support/users/wmchugh/)
 * (@wmchugh)
 * [6 years, 6 months ago](https://wordpress.org/support/topic/redirect-from-http-to-https-3/#post-12104599)
 * I have looked into it and they are running NGINX on top of Apache. Does that 
   change whether .htaccess will work? Their support is saying that .htaccess will
   work, and their recommended way of achieving redirection to https is .htaccess.
 *  [autotutorial](https://wordpress.org/support/users/autotutorial/)
 * (@autotutorial)
 * [6 years, 6 months ago](https://wordpress.org/support/topic/redirect-from-http-to-https-3/#post-12104945)
 * they are right I checked your api rest and it works with mod_rewrite, wordpress
   checks if it is https via port 443 or if set to 1 https,
    You can create test.
   php
 *     ```
       <?php
       echo $_SERRVER['SERVER_PORT'];
       ```
   
 * Add this constant into wp-config.php before ABSPATH
 *     ```
       //Without end slash
       define('WP_HOME','https://your site.com');
       define('WP_SITEURL','https://your site.com');
       ```
   
 * This constant will use this regardless of the value of the database
 *  Thread Starter [wmchugh](https://wordpress.org/support/users/wmchugh/)
 * (@wmchugh)
 * [6 years, 6 months ago](https://wordpress.org/support/topic/redirect-from-http-to-https-3/#post-12105140)
 * I made that addition to wp-config.php, along with the suggested change to .htaccess.
   It now works. I tried it again without the config change, and it worked. Maybe
   someone cleared a chache for me on the server, or … I don’t know, it’s working
   now from .htaccess and my javascript hack is removed. Thank you for your help
   🙂
 *  [freelancerindia](https://wordpress.org/support/users/freelancerindia/)
 * (@freelancerindia)
 * [6 years, 4 months ago](https://wordpress.org/support/topic/redirect-from-http-to-https-3/#post-12300126)
 * [@autotutorial](https://wordpress.org/support/users/autotutorial/) [@wmchugh](https://wordpress.org/support/users/wmchugh/)
   
   You can remove all redirection from WordPress account and can do it through .
   htaccess file. Just use the below example: RewriteEngine On RewriteCond %{HTTP_HOST}
   ^freelancer\.india\.to [NC] RewriteCond %{SERVER_PORT} 80 RewriteRule ^(.*)$ 
   [https://freelancer.india.to/$1](https://freelancer.india.to/$1) [R,L]
 * Source: [https://hoststud.com/resources/how-to-manually-redirect-from-http-to-https-through-htaccess-file.444/](https://hoststud.com/resources/how-to-manually-redirect-from-http-to-https-through-htaccess-file.444/)

Viewing 7 replies - 1 through 7 (of 7 total)

The topic ‘Redirect from http to https’ is closed to new replies.

 * In: [Fixing WordPress](https://wordpress.org/support/forum/how-to-and-troubleshooting/)
 * 7 replies
 * 1 participant
 * Last reply from: [freelancerindia](https://wordpress.org/support/users/freelancerindia/)
 * Last activity: [6 years, 4 months ago](https://wordpress.org/support/topic/redirect-from-http-to-https-3/#post-12300126)
 * Status: not resolved

## Topics

### Topics with no replies

### Non-support topics

### Resolved topics

### Unresolved topics

### All topics
