0

I deployed my wordpress site in Google Cloud Compute Engine. To enable SSL I followed the the steps outlined here https://www.onepagezen.com/free-ssl-certificate-wordpress-google-cloud-click-to-deploy

  1. Install Certbot Client
  2. Generate Certificates
  3. Configure the Certificates
  4. Enable HTTPS Redirect
  5. Restart Apache Server
  6. Update WordPress URLs
  7. Configure SSL Auto-Renewal

Edit /etc/apache2/sites-available/default-ssl.conf

<IfModule mod_ssl.c>
    <VirtualHost _default_:443>
        ServerAdmin webmaster@localhost
        DocumentRoot /var/www/html

        <Directory /var/www/html>
            Options Indexes FollowSymLinks MultiViews
            AllowOverride All
            Order allow,deny
            Allow from all
            Require all granted
        </Directory> 
    ...

and /etc/apache2/sites-available/wordpress.conf

<VirtualHost *:80>

  ServerAdmin webmaster@localhost
  DocumentRoot /var/www/html
  ServerName mydomain.com
  ServerAlias mydomain.com
  Redirect permanent / https..mydomain.com

  <Directory />
    Options FollowSymLinks
    AllowOverride None
  </Directory>

  <Directory /var/www/html/>
    Options Indexes FollowSymLinks MultiViews
    AllowOverride All
    Order allow,deny
    Allow from all
  </Directory>

    ScriptAlias /cgi-bin/ /usr/lib/cgi-bin/
  <Directory "/usr/lib/cgi-bin">
    AllowOverride None
    Options +ExecCGI -MultiViews +SymLinksIfOwnerMatch
    Order allow,deny
    Allow from all
  </Directory>

  ErrorLog ${APACHE_LOG_DIR}/error.log
  # Possible values include: debug, info, notice, warn, error, crit,
  # alert, emerg.
  LogLevel warn
  CustomLog ${APACHE_LOG_DIR}/access.log combined
</VirtualHost>

After setting everything up, I run:

sudo a2ensite default-ssl
sudo a2enmod ssl
sudo service apache2 restart

SSL works fine for the backend and the landing page. However for all other pages I get a 404. When I switch form custom permalinks to simple permalinks the pages are accessible again. Any ideas what might be causing the problem?

4
  • did you adjust wp's standard htaccess file?
    – Pat_Morita
    May 5, 2019 at 18:37
  • @Pat_Morita as I understand correctly, the htaccess file gets adjusted automatically by changing the permalink settings in wordpress. I actually tested it and the htaccess file gets overwritten when I change the settings. May 6, 2019 at 7:25
  • Is Redirect permanent / https..mydomain.com actually how it is or is this shorthand intended to communicate that all requests are port 80 should be redirected to 443? May 6, 2019 at 14:43
  • @Artjom Zabelin - Do you have some kind of a load balancer active?
    – twelvell
    May 7, 2019 at 13:42

2 Answers 2

0

This is a pretty common problem. Unfortunately there are dozens of possible causes, which may be on the server level as well as the WordPress level. Therefore, it is impossible to pinpoint a solution for you.

One thing you know is that the server settings you mention are working correctly at least in part, in the sense that they read the WordPress .htaccess file, because that's where the redirects for pretty permalinks are stored. Still, there might be trouble if somewhere down the track there is a redirect to http, which the server might then refuse to serve (this seems to be a problem with Google's service).

Any server related trouble is off topic here, but there are a couple of things on the WordPress level you could try:

  • Disable all plugins (except your SSL-plugin) and resave the permalinks. This makes sure no plugins are redirecting to http
  • Make sure there are no .htaccess files in subdirectories inadvertently redirecting to http.
  • Add $_SERVER['HTTPS']='on'; to your config.php file to tell WordPress that is is supposed to serve all pages with https. Sometimes the server setup is so complex WordPress cannot determine this itself.
  • Alternatively, force your whole domain to https with these lines in .htaccess:

    RewriteEngine On

    RewriteCond %{HTTPS} !=on

    RewriteRule ^/?(.*) https://%{SERVER_NAME}/$1 [R,L]

0

If you have a load balancer, try to add following line in wp-config.php

$_SERVER['HTTPS']='on';
1
  • @Artyom Zabelin did this helped you?
    – twelvell
    May 11, 2019 at 22:39

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.