0

I am running an Ubuntu instance on GCP with apache2 and php 7. More so, I am using CloudFlare as my SSL certificate provider.

In GCP, if I configure "allow http and https", the website works both for http and https. Though I have to specifically add the https prefix to domain, so that it will work securely.

But, if I disallow the http in GCP, and allow only https, I am unable to enter my website whatsoever, even with adding the https prefix.

Is there any configuration I am missing in GCP or Apache2?

I'd appreciate your help.

2
  • I found a partial workaround solution via Cloudflare, where there's an option to redirect all http to https via their configuration panel. Though I guess there might be a solution to my issue via GCP as well, that I don't know of yet
    – bentz123
    May 11, 2018 at 11:08
  • HSTS Preload would help, as would using an .app domain May 11, 2018 at 11:59

2 Answers 2

1

Try to simple add redirection rule in apache configuration for listen on port 80

<VirtualHost *:80>
        Redirect permanent / https://your_domain_name.com
</VirtualHost>
0

Apache allows you to create redirections which you can use to suit your needs:

Temporary redirect with Redirect

<VirtualHost *:80>
    ServerName www.domain1.com
    Redirect / http://www.domain2.com
</VirtualHost>

<VirtualHost *:80>
    ServerName www.domain2.com
    . . .
</VirtualHost>

Temporary redirects with RedirectMatch

<VirtualHost *:80>
    ServerName www.domain1.com
    RedirectMatch ^/(.*)$ http://www.domain2.com/$1
</VirtualHost>

<VirtualHost *:80>
    ServerName www.domain2.com
    . . .
</VirtualHost>

Permanent redirects

<VirtualHost *:80>
    ServerAdmin [email protected]
    ServerName domain1.com
    ServerAlias www.domain1.com    
    DocumentRoot /var/www/domain1.com/public_html
    ErrorLog ${APACHE_LOG_DIR}/error.log
    CustomLog ${APACHE_LOG_DIR}/access.log combined
    RedirectMatch permanent ^/(.*)$ http://domain2.com/$1
</VirtualHost>

Further information can be found in this documentation link

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .