WordPress SSL htaccess code – Rewrite SSL, RewriteCond Server Port

Home Forums BulletProof Security Pro WordPress SSL htaccess code – Rewrite SSL, RewriteCond Server Port

Viewing 15 posts - 46 through 60 (of 117 total)
  • Author
    Posts
  • #27265
    Paulin Halenria
    Participant

    [Topic has been merged into this relevant Topic]
    I made search on the website and didn’t find the correct code. I’d like to merge those codes but no idea how to perform correctly.

    # Rewrite www to non-www
    RewriteEngine On
    RewriteBase /
    RewriteCond %{HTTP_HOST} ^www\.example\.com$ [NC]
    RewriteRule ^(.*)$ http://example.com/$1 [R=301,L]
    RewriteRule ^index\.php$ - [L]
    
    # WP REWRITE LOOP START
    RewriteEngine On
    RewriteBase /
    RewriteCond %{HTTPS} !=on
    RewriteCond %{SERVER_PORT} ^80
    RewriteRule (.*) https://%{HTTP_HOST}%{REQUEST_URI} [R,L]
    RewriteRule ^index\.php$ - [L]
    
    Indeed, I want my website been only reachable by
    https://example.com
    So I need to redirect all requests from
    http://example.com
    http://www.example.com
    https://www.example.com

    And the second part, no idea if it could work… I’m using Polylang to have my website bilingual using two different domains.So, I need for the same website, have the requests from

    http://example2.com
    http://www.example2.com
    https://www.example2.com
    to https://example2.com

    But as already said, no idea if such a setup will be possible or not…. My first idea would be

    # Rewrite everything like a pro
    RewriteEngine On
    RewriteBase /
    RewriteCond %{HTTP_HOST} ^www\.example\.com$ [NC]
    RewriteRule ^(.*)$ https://example.com/$1 [R=301,L]
    RewriteRule ^index\.php$ - [L]
    RewriteCond %{HTTP_HOST} ^www\.example2\.com$ [NC]
    RewriteRule ^(.*)$ https://example2.com/$1 [R=301,L]
    RewriteRule ^index\.php$ - [L]RewriteCond %{HTTPS} !=on
    RewriteCond %{SERVER_PORT} ^80
    RewriteRule (.*) https://%{HTTP_HOST}%{REQUEST_URI} [R,L]
    RewriteRule ^index\.php$ - [L]

    Thanks
    Cedric

    #27268
    AITpro Admin
    Keymaster
    #28226
    Ruud van der Veer
    Participant

    Hi,

    I’m completely new here; I hope this is te right place for posting my questing. First: thanks for this great Pro-version I bought last Friday.

    My question: see the topic title. Those redirects I made with

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

    in the .httaccess file. I experienced a lot with it in BP Pro, but noting was successful. And I do have problems with understanding English. Would you be so kind to explain it to me step by step, please?

    Thanks in advance,

    Ruud

    #28230
    AITpro Admin
    Keymaster

    @ Rudd Van Deer – See this reply in this same forum topic for instructions on how to do that.
    http://forum.ait-pro.com/forums/topic/wordpress-ssl-htaccess-code-rewrite-ssl-rewritecond-server_port/#post-7233

    #28297
    rafaelmagic
    Participant

    Load Balancers and SSL Redirect

    If Apache is behind a Load Balancer , Pound, HaProxy, Nginx.

    Then your  requests coming from the load balancer arrive over HTTP to Apache, so the HTTPS variable is set to OFF. Therefore, .htacess is reading HTTPS OFF from the server.

    However, Apache Server does have a SSL variable called HTTP_X_FORWARDED_PROTO that can be used.

    #WP REWRITE LOOP START for Load Balancers
    RewriteCond %{HTTP:X-Forwarded-Proto} !https 
    RewriteRule ^(.*)$ https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]

    or

    #WP REWRITE LOOP START- For Load Balancers
    RewriteEngine on
    RewriteCond %{HTTP:X-Forwarded-Proto} !https
    RewriteRule .* https://%{HTTP_HOST}%{REQUEST_URI} [R,L]
    

    Directions:

    WordPress General Settings:
    WordPress Address (URL)    https://www.your-domain-name.com
    Site Address (URL)                https://www.your-domain-name.com

    1. Copy this .htaccess code below to this BPS Root Custom Code text box: CUSTOM CODE WP REWRITE LOOP START: Add www to non-www/non-www to www code here
    2. Click the Save Root Custom Code button.
    3. Go to the BPS Security Modes page and click the Root Folder BulletProof Mode Activate button.

    #28583
    Paul
    Participant

    [Topic has been merged into this relevant Topic]
    I am currently using the following to send index.htm to the root .co.uk

    RewriteEngine On
    RewriteBase /
    RewriteCond %{HTTP_HOST} ^mysite\.co\.uk$ [NC]
    RewriteRule ^(.*)$ http://www.%{HTTP_HOST}%{REQUEST_URI} [R,L]
    RewriteRule ^index\.htm$ / [R,L]

    I am going to move to ssl and was wondering what i needed to add to this and also what i would need to redirect all pages from http to https?

    In above would i just add an s to any http like

    RewriteEngine On
    RewriteBase /
    RewriteCond %{HTTPs_HOST} ^mysite\.co\.uk$ [NC]
    RewriteRule ^(.*)$ https://www.%{HTTP_HOST}%{REQUEST_URI} [R,L]
    RewriteRule ^index\.htm$ / [R,L]

    Would this do the http to https bit on a like for like

    RewriteEngine On
    RewriteCond %{HTTPS} off
    RewriteRule (.*) https://%{SERVER_NAME}/%$1 [R,L]
    #28586
    AITpro Admin
    Keymaster

    @ Paul – See this reply in this same forum topic for examples of SSL/HTTPS htaccess code and how/where to add it to BPS Custom Code (or just generally in an htaccess file that is not a BPS htaccess file):  http://forum.ait-pro.com/forums/topic/wordpress-ssl-htaccess-code-rewrite-ssl-rewritecond-server_port/#post-7233  Since you are rewriting a index.htm file instead of an index.php then be sure to change index.php to index.htm in your htaccess code that you use/create.

    #28590
    Paul
    Participant

    Thanks so am i right in thinking this would do both?

    # WP REWRITE LOOP START
    RewriteEngine On
    RewriteBase /
    RewriteCond %{HTTPS} !=on
    RewriteCond %{SERVER_PORT} ^80
    RewriteRule (.*) https://%{HTTP_HOST}%{REQUEST_URI} [R,L]
    RewriteRule ^index\.htm$ - [L]

    Changed the .php to .htm

    #28593
    AITpro Admin
    Keymaster

    I should have asked these questions first:  Are you just trying to redirect the index.htm file to the home page of this site?  Is the index.htm file under a WordPress installation folder/website?  Is this website a separate HTML website?

    #28601
    Paul
    Participant

    OK.
    one of my WordPress sites was better suited to not being a wordpress site so i made it a “normal” htm website.
    Initially it was not redirecting the index.htm to .co.uk inmstead i could access .co.uk/index.htm too but this solved that

    RewriteEngine On
    RewriteBase /
    RewriteCond %{HTTP_HOST} ^mysite\.co\.uk$ [NC]
    RewriteRule ^(.*)$ http://www.%{HTTP_HOST}%{REQUEST_URI} [R,L]
    RewriteRule ^index\.htm$ / [R,L]

    I now would like to make the whole site SSL over https so wanted to redirect everything from http to https and still have code above doing its job on SSL server.

    Hope that makes some sense?

    #28602
    AITpro Admin
    Keymaster

    Ok then the code you posted in your previous reply should work fine or you may need to alter it slightly by changing the RewriteRule to:  RewriteRule ^index\.htm$ / [R,L]. Try the code you posted in your previous reply and that does not work then try changing the RewriteRule.

    #28609
    Paul
    Participant

    Ok thanks, i,ll give both a try

    # WP REWRITE LOOP START
    RewriteEngine On
    RewriteBase /
    RewriteCond %{HTTPS} !=on
    RewriteCond %{SERVER_PORT} ^80
    RewriteRule (.*) https://%{HTTP_HOST}%{REQUEST_URI} [R,L]
    RewriteRule ^index\.htm$ / [R,L]

    and

    # WP REWRITE LOOP START
    RewriteEngine On
    RewriteBase /
    RewriteCond %{HTTPS} !=on
    RewriteCond %{SERVER_PORT} ^80
    RewriteRule (.*) https://%{HTTP_HOST}%{REQUEST_URI} [R,L]
    RewriteRule ^index\.htm$ - [L]

    My host gave for the redirect but i,ll try that last 😉

    RewriteCond %{HTTPS} on
    RewriteCond %{HTTP_HOST} !^www\.(.*)$ [NC]
    RewriteRule ^(.*)$ https://www.%{HTTP_HOST}%{REQUEST_URI} [R=301,L]
    #28946
    dtyler1
    Participant

    My site is no longer directing all traffic to use the https://www.domain.com version of my website. I’ve followed the instructions here testing both code snippets and neither of them are working now (new update to BPS Pro?).

    #28950
    AITpro Admin
    Keymaster

    @ dtyler1 – While I was logged into your site and looking at the API server error issue/problem, I noticed that you were not using any HTTPS/SSL htaccess code so I added it in BPS Custom Code.  If that HTTPS/SSL htaccess code is causing a problem on your site then remove it, but after adding the HTTPS/SSL htaccess code I checked your site and everything was working fine.  Also remove any/all HTTPS/SSL htaccess code that you have added to BPS Custom Code.

    #28964
    dtyler1
    Participant

    I appreciate the code added, but for some unknown reason traffic from http:// is not being redirected to https://

Viewing 15 posts - 46 through 60 (of 117 total)
  • You must be logged in to reply to this topic.