Search code examples
.htaccesshttp-redirecthttpsgoogle-cloud-platformbitnami

htaccess - IP canonicalization to HTTPS


Bitnami wordpress on Google Cloud.

Ok, the below code, diverts all to https non-www which works great, but the issue is we can't get the dedicated IP to redirect to https url. Please see below;

RewriteEngine on


<ifModule mod_rewrite.c>
RewriteBase /

# IP REDIRECT CONANIZATION
RewriteCond %{HTTP_HOST} ^00\.00\.93\.114$
RewriteRule ^(.*)$ https://example.co.uk/$1 [L,R=301]


### WORKING HTTP to HTTPS / NON-WWW - WORKS

#if not example.co.uk then redirect to example.co.uk
RewriteCond %{HTTP_HOST} !^example\.co.uk$ [NC]
RewriteRule .* http://example.co.uk%{REQUEST_URI} [L,R=301]

#if not https
RewriteCond %{HTTPS} off
#redirect to https
RewriteRule .* https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]

</IfModule>

Solution

  • Bitnami Engineer here.

    From the configuration file you are sharing here, it seems to me that you are trying to redirect all the incoming requests to https://example.co.uk, is this true?

    In order to do so, you can edit the /opt/bitnami/apache2/conf/bitnami/bitnami.conf file and set the following lines

    <VirtualHost _default_:80>
    RewriteEngine On
    RewriteCond %{HTTP_HOST} !^example.co.uk$
    RewriteCond %{HTTP_HOST} !^(localhost|127.0.0.1)
    RewriteRule ^(.*)$ https://example.co.uk$1 [R=permanent,L]
    ...
    
    <VirtualHost _default_:443>
    RewriteEngine On
    RewriteCond %{HTTP_HOST} !^example.co.uk$
    RewriteCond %{HTTP_HOST} !^(localhost|127.0.0.1)
    RewriteRule ^(.*)$ https://example.co.uk$1 [R=permanent,L]
    ...
    

    More information here:

    https://docs.bitnami.com/google/components/apache/#how-to-access-my-application-from-only-one-domain