Support » Fixing WordPress » Forcing http to https and non-www. to www.

  • Eric4381

    (@eryk4381)


    I saw this post already but I cant reply to it so I am starting another. I am trying to force all traffic:

    From
    http://example.com
    http://www.example.com
    https://www.example.com

    to

    https://example.com

    I think I have most of this except http://example.com is not forwarding currently. here is my htaccess configs:
    <IfModule mod_rewrite.c>
    RewriteEngine On
    RewriteBase /
    RewriteRule ^index\.php$ – [L]
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteRule . /index.php [L]

    #Master Rule to chagne HTTP and WWW to HTTPS
    RewriteEngine on

    RewriteCond %{HTTP_HOST} ^www\.(.*)$ [NC]
    RewriteRule ^(.*)$ https://%1/$1 [R=301,L]

    RewriteCond %{HTTPS} !on
    RewriteRule (.*) https://%{HTTP_HOST}%{REQUEST_URI} [R=301,L]

    What am I missing

    The page I need help with: [log in to see the link]

Viewing 15 replies - 1 through 15 (of 18 total)
  • autotutorial

    (@autotutorial)

    Your server creates the door variable 443 or https on or 1, obviously you must have https already active on your server.

    try this script if you can identify what you use for https. test.php

    <?php
    print_r($_SERVER);

    call test.php from the browser https://yourdomain.com/test.php
    The https rules will take precedence over everything, you have to put them just below RewriteBase /
    If test.php gives you $_SERVER[‘HTTPS’] = ‘On’;

    RewriteCond %{HTTPS} !On [OR]
    RewriteCond %{HTTP_HOST} !^yourdomain\.com [NC]
    RewriteRule [^/]? https://yourdomain.com%{REQUEST_URI} [R=301,L]

    Valid for forwarding on a single domain does not use the variable HTTP_HOST simply use your domain, also to control the domain use your domain otherwise even the domains of fourth level are valid example http://www.forum.yourdomain.com or http://forum.yourdomain.com 🙂

    Eric4381

    (@eryk4381)

    My Site has been up for a while now with only https so that part is done. However I want to catch those people that dont know the difference between www,http,https,etc and kick them right to my site. That is the code i need!! Should I replace all of what I have in my htaccess with this?

    RewriteCond %{HTTPS} !On [or]
    RewriteCond %{HTTP_HOST} ^www\.yourdomain\.com [NC]
    RewriteRule [^/]? https://yourdomain.com%{REQUEST_URI} [R=301,L]

    autotutorial

    (@autotutorial)

    if you have only one channel use the negation also for htaccess is the character! !^yourdomain\.com means if different from yourdomain.com

    Eric4381

    (@eryk4381)

    I’m sorry, can you elaborate on what you just said?

    autotutorial

    (@autotutorial)

    Redirect from http://www.forum.yourdomain.com http://forum.yourdomain.com https://www.forum.yourdomain.com
    https://forum.yourdomain.com
    https://www.yourdomain.com http://yourdomain.com

    To https://yourdomain.com

    RewriteEngine On
    RewriteBase /
    RewriteCond %{HTTP_HOST} !^yourdomain\.com [NC,OR]
    RewriteCond %{HTTPS} !On
    RewriteRule [^/]? https://yourdomain.com%{REQUEST_URI} [R=301,L]

    Sorry 😀

    Eric4381

    (@eryk4381)

    AHH! ok. Thank you. Now when I try that and comment out the code I had I get redirect loops and even https://example.com doesn’t come up.

    autotutorial

    (@autotutorial)

    Exist $_SERVER[‘HTTPS’] =’On’ ?
    I edited the code six minutes ago

    Eric4381

    (@eryk4381)

    So this is all i have currently being used in htaccess but i still get a too many redirects

    # 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]

    # FOrce ALL to HTTPS
    RewriteEngine On
    RewriteBase /
    RewriteCond %{HTTP_HOST} !^stonesorganics\.com [NC,OR]
    RewriteCond %{HTTPS} !On
    RewriteRule [^/]? https://stonesorganics.com%{REQUEST_URI} [R=301,L]

    autotutorial

    (@autotutorial)

    can you create a test.php page?

    <?php
    print_r($_SERVER);

    I need the url of this page

    Eric4381

    (@eryk4381)

    autotutorial

    (@autotutorial)

    <IfModule mod_rewrite.c>
    # FOrce ALL to HTTPS
    RewriteEngine On
    RewriteBase /
    RewriteCond %{HTTP_HOST} !^stonesorganics\.com [NC,OR]
    RewriteCond %{HTTPS} !on
    RewriteRule [^/]? https://stonesorganics.com%{REQUEST_URI} [R=301,L]
    </IfModule>
    # 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>

    Prove this with ‘on’ lowercase.

    Eric4381

    (@eryk4381)

    That gave me a 500 error on all pages. Did you post then modify again by chance?

    autotutorial

    (@autotutorial)

    yes but I have to understand why .. I copied your code .. It may be because it sees ifmodule RewriteEngine and RewriteBase twice.
    try like this

    # BEGIN WordPress
    
    <IfModule mod_rewrite.c>
    # FOrce ALL to HTTPS
    RewriteEngine On
    RewriteBase /
    RewriteCond %{HTTP_HOST} !^stonesorganics\.com [NC,OR]
    RewriteCond %{HTTPS} !on
    RewriteRule [^/]? https://stonesorganics.com%{REQUEST_URI} [R=301,L]
    RewriteRule ^index\.php$ – [L]
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteRule . /index.php [L]

    make sure you nest properly ifmodule, if you have two open only two closed will exist.

    Eric4381

    (@eryk4381)

    That also gets me a 500 error

    autotutorial

    (@autotutorial)

    RewriteEngine On
    RewriteBase /
    RewriteCond %{HTTP_HOST} !^stonesorganics\.com [NC,OR]
    RewriteCond %{HTTPS} !^on
    RewriteRule [^/]? https://stonesorganics.com%{REQUEST_URI} [R=301,L]
    RewriteRule ^index\.php$ – [L]
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteRule . /index.php [L]

    sorry this code works for me i have no more ideas.

Viewing 15 replies - 1 through 15 (of 18 total)
  • The topic ‘Forcing http to https and non-www. to www.’ is closed to new replies.