How to configure 503 status for HTTPS? - css

I set up a maintenance page for my site so when users visit, they are returned with the 503 status and redirected to a custom maintenance.php page. So it works fine and I can clearly see in my browsers that it is properly returning 503 as long as I manually enter URL's in my search address bar.
The issue is if someone clicks a link to certain pages from a Referrer, let's say from Facebook, it will redirect them to the maintenance.php page but for some reason it fails to load the CSS files and images associated with it. The CSS files and images suddenly return a 503 status as well.
My site by default will also redirect "http" pages to use "https" and "www". If I run the same page in just "http", the CSS files and images will load.
Then, if I run the page in "https" with no "www" in the URL, the page will load the CSS files and images.
So it seems as long as "https" and "www" are both in the URL, the page, its' CSS files, and its' images will all return 503.
My 503 status is configured in my .htaccess file:
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REMOTE_ADDR} !^123\.45\.67\.89$
RewriteCond %{DOCUMENT_ROOT}/maintenance.php -f
RewriteCond %{DOCUMENT_ROOT}/maintenance.enable -f
RewriteCond %{SCRIPT_FILENAME} !maintenance.php
RewriteRule ^.*$ /maintenance.php [R=503,L]
ErrorDocument 503 /maintenance.php
Header Set Cache-Control "max-age=0, no-store"
The server is running Apache. Is there a configuration I can use that will make sure the CSS files and images load when someone clicks a link that includes "https" and "www" in the URL?
Edit: It also seems the pages with this issue do not have their URL's redirect to maintenance.php either. Although they still display the maintenance.php content despite this.

It turns out the solution was simple. In my maintenance.php I just needed to change the relative paths to absolute paths instead for the CSS files and images by adding a "/" in front.
i.e.
Originally was:
<link href="css/maintenance.css" rel="stylesheet" type="text/css">
Changed to:
<link href="/css/maintenance.css" rel="stylesheet" type="text/css">

Related

How do I make the landing page of website appear on Google and not "Index of /"?

I have recently made my WordPress website live and want it to be visible on Google Search. However, when specifically searching for the website, Google does not show the site title or description entered in WordPress, but rather "Index of /" and a bit of server info as the page summary. Does anyone recognize this, and have some ideas on how to fix this?
Apache2 is running on an Ubuntu 18.04 server and everything is updated. I have both an index.html file and obviously an index.php file in the DocumentRoot directory specified in the Virtual Host file for apache. And have specified to use index.php first in the .htaccess file. I've also tried to add the URL of the page to Google Search Console and added a sitemap, but with no effect.
You can add these lines to .htaccess files (its located in root of the website). What it does its redirects any trafic you got on http://example.com to https://example.com Please check both locations in separate browsers (and again with removed cache) on how it works. SOmetimes apache can be configured so it wouldn't work out of the box (like it can require additional fixes to redirection code or to the additional blocks etc...)
RewriteEngine On
RewriteCond %{HTTPS} !=on
RewriteRule ^/?(.*) https://%{SERVER_NAME}/$1 [R,L]

HTTPS image request turns into an HTTP request in Wordpress

I have a subdomain static.vivicheruti.com that points to vivicheruti.com/static.
I'm using Wordpress 5.2.1
I have a test page where I wrote this tag:
<img src="https://static.vivicheruti.com/Nube.png">
When I access the page, the image doesn´t show AND I get this "error"
Mixed Content: The page at 'https://vivicheruti.com/prueba/' was loaded over HTTPS, but requested an insecure image 'http://vivicheruti.com/static/Nube.png'. This content should also be served over HTTPS.
The URL is resolved OK but why the HTTP?
So I host my site on Siteground. I asked for help there but they say this is a Wordpress developer issue...
this https to http only happens in this case and I don´t know who is resolving this.
Any clues? Pls just ask for any extra information you need.
I have Cloudflare as part por Siteground's plan.
Updated --> FIXED (.htaccess)
#RewriteEngine On
#RewriteBase /
#RewriteCond %{HTTP_HOST} !=vivicheruti.com [NC]
#RewriteRule ^(.*)$ https://vivicheruti.com/$1 [R=301,L]
it said http instead of https in the last rule.

include css and images when rewriting url to remote server

I have an apache http server and I want to redirect certain URL to an external(remote) site, so I set the following line in the httpd.conf file :
RewriteRule ^/datafeeds/customer_feed.jsp http://othersite.com/datafeeds/customer_feed.jsp [P]
the problem is that the page is returning without the css and images (all resources) because it's put as relative paths in the remote site .... I need all the css and images to appear normally as if I am opening the remote site from the browser, how can I do it?
I simply modified the rule to include all resources :
RewriteRule ^/datafeeds/(.+)$ http://othersite.com/datafeeds/$1 [P]

Mixed content - SSL http/https issue

Approximately 2 months ago I installed a SSL certificate on my site, catherinerushforth.com. I changed the site and WordPress URL in the admin area of WordPress to include https:// instead of http://. All was fine.
Then, about 2 weeks ago I started to have a problem with "Mixed Content" errors on all pages except the main home page. There doesn't seem to be an issue when viewing the site with Safari but there is a problem with Chrome, Firefox and Internet Explorer. I inspected the Javascript console in Chrome (as an example) and saw multiple "Mixed Content" errors
This is what I have do so far to try and fix these mixed content errors:
Changed http:// to https:// in the WordPress Admin section for the site and WordPress URLs (Settings/General)
I've added "define('FORCE_SSL_ADMIN', true);" to the top of the wp-config.php file.
I've added the following piece of code to the .htaccess file:
RewriteEngine on
RewriteCond %{HTTP_HOST} ^catherinerushforth.com [NC]
RewriteRule ^(.*)$ https://catherinerushforth.com/$1 [L,R=301]
With this code I get "ERR_TOO_MANY_REDIRECTS"
I've also tried the plugin, WordPress HTTPS (SSL).
None of the above have worked.
Does anyone know what I am doing wrong and/or have any suggestions as to how I can fixed this issue?
Many thanks.
WordPress version: 4.2.2
Theme: X-theme v.4 (although issue was the same in previous version of this theme)
Site: catherinerushforth.com
UPDATE
If I simply remade each page for my site (which I will probably have to do at some point due to X-Theme now using their CornerStone page builder) would this ensure all links were https:// and not http://?
Remove
define('FORCE_SSL_ADMIN', true);
from wp-config.php, be sure you have changed http:// to https:// in WordPress Admin, and then force SSL for front and backends with this in .htaccess above the WordPress rewrite block:
RewriteEngine On
RewriteCond %{SERVER_PORT} 80
RewriteRule ^(.*)$ https://catherinerushforth.com/$1 [R=301,L]
That only forces SSL; you still need to find the site resources which are loading non-SSL.
So use the developer tools in Firefox (or Firebug) or Chrome or Safari or IE to see the errors with specific site resources.
And:
• you should change URLs of media items and links in the post/page content to https so they don't depend on the redirect in .htaccess. Search RegEx is a good plugin to be able to search and replace (optionally with grep) through all posts, pages, excerpts, comments, titles and meta. And, interconnectit.com WordPress Serialized PHP Search Replace Tool can be used to find/replace in the entire database, i.e. metadata, GUIDs and widget content, etc.
• You may need to change to a relative path for images in CSS files, i.e. background-image: url(http://example.com/themes/wp-content/theme/images/image.jpg) to background-image: url(images/image.jpg)
• You may need to remove the http from absolute paths in php theme files, i.e. change 'http://example.com/image.jpg' to '//example.com/image.jpg'; that will allow your resources to default to https.
RewriteEngine On
RewriteCond %{HTTPS} !=on [NC]
RewriteRule ^ https://%{SERVER_NAME}%{REQUEST_URI} [R,L]
Source
So I had this issue on image urls being returned as http://https://website.com/image.jpg. What I did was use the Velvet URL plugin to rewrite the urls for all content from http://https://websiteurl to https://websiteurl. This fixed the issue for me. Cheers
Using ubuntu 16.04, letsencrypt, nginx, apache2, wordpress. For me
1. adding redirect in `/etc/apache2/sites-enabled/000-default.conf` didn't work (too many redirects)
2. adding RewriteRule in .htaccess didn't work (too many redirects)
Finally I installed really-simple-ssl plugin from wordpress and it worked like charm.

HTTPS on dev server - issues

I copied a live woocommerce site back to the dev server. The live site uses https. So when I tried accessing it on the dev server, it redirected me to the live site. I figured the issue was the .htaccess file. I tried editing it, but the file is encrypted. So I just removed it all together. That stopped the redirecting, and I was able to access the front-end of the dev site. However when I try to access the wp-admin or wp-login.php I get a 404. I also noticed that the broswer changed from http to https. So there's something still trying to make the website run under https.
What I've tried:
I deactivated woocommerce plugin (by renaming it) but that didn't
help.
I also searched in the database for instances of https:// but I
could not find any that related to the website.
I also found and removed a cert.html file in the root which I think
it's related to the https certification, but I still can't access
the backend.
And last, I tried to add a new .htaccess file with the basic
wordpress permalinks in it, but that just gave 500 server errors.
Can anyone give some pointers where to look? Or what could be causing the browser to use https, instead of http.
It looks like you need to change your site URL to point to the right place. Since you can't log in (it'll redirect you to the wrong site URL), you need to change this in your wp-config.php file (see this link for more info):
define('WP_HOME','http://example.com');
define('WP_SITEURL','http://example.com');
After that, and hopefully with the default wordpress rules, you should be able to log in to the admin pages.
# BEGIN WordPress
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
</IfModule>
# END WordPress
The above assumes that your wordpress site is at /.

Resources