• 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://%{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 to see the link]

Viewing 7 replies - 1 through 7 (of 7 total)
  • .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/
    Wordpress guide for https, W3 total cache and other https://www.ads-software.com/support/article/nginx/

    Use the Better Search Replace plugin to change every instance of ‘https://youriste.com&#8217; to ‘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.

    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

    (@wmchugh)

    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.

    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

    (@wmchugh)

    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 ??

    @autotutorial @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 [R,L]

    Source: 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.