0

I have a few sites hosted on an apache server. Most of them can be accessed via http and https. One of them may only be accessed over http. Attempts to acccess it via https must be redirected to the 404.php page (except for attempts to access the error page itself - those should be allowed).

I can get a custom text message to appear with the ErrorDocument directive, but I'm having trouble figuring out how to send the users to the 404 page. Here's what the config looks like:

<IfModule mod_ssl.c> <VirtualHost *:443> ServerName myserver ServerAlias myserver SSLEngine On SSLProxyEngine On SSLCertificateFile /path/to/certificatefile.pem SSLCertificateKeyFile /path/to/keyfile.pem Include /etc/ssl-apache.conf DocumentRoot /usr/local/website Redirect 404 / # This works! ErrorDocument 404 "Not here!" # This tries to redirect to the path to the 404.php file but does *not* work #ErrorDocument 404 /wordpress/wp-content/themes/Theme1/404.php ErrorLog ${APACHE_LOG_DIR}/error.log CustomLog ${APACHE_LOG_DIR}/access.log combined <Directory "/usr/local/website/html/wordpress"> AllowOverride All Require all granted </Directory> <Directory /> # required for apache 2.4+ AllowOverride All Require all granted Options +Includes XBitHack on # allows CORS for static content Header set Access-Control-Allow-Origin * </Directory> </VirtualHost> </IfModule> 

Trying to redirect to the 404.php using ErrorDocument results in:

The requested URL / was not found on this server.

Additionally, a 404 Not Found error was encountered while trying to use an ErrorDocument to handle the request.

I also tried ErrorDocument 404 https://myserver/wordpress/wp-content/themes/Theme1/404.php But that resulted in "too many redirects".

How can I get all requests to this VirtualHost to be redirected to the custom 404 page?

2

1 Answer 1

-1

Remove the line:

Redirect 404 / 

And use your original:

ErrorDocument 404 https://myserver/wordpress/wp-content/themes/Theme1/404.php 
3
  • That's a good point - I think my wording was not clear. I don't want to redirect them to http://....404.php, I want everything to redirect to https://...404.php - except for attempts to access that error page itself. Commented Jun 21, 2017 at 14:57
  • Sorry, I misunderstood. Try my edit. Commented Jun 21, 2017 at 18:01
  • That doesn't seem to be doing anything. I think ErrorDocument needs to work with something that generates the error code. I was using Redirect 404 / to do that. Removing it just results in content from the next virtualhost on 443 to be returned. Commented Jun 21, 2017 at 19:39

You must log in to answer this question.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.