Having issues setting custom 404 page...

Hey all,


I'm not sure if I'm missing a step, I created a custom 404 page ("404.html") and it's in the root of the website folder. Under Websites (tab) > Server Website, I click Advanced Settings and set the custom error page to "/404.html", yet entering, say, website.com/abc, still brings me to the generic Apache 404 page.


I also tried specifying the 404 page as "/404" and "404.html", and I tried adding it to the index file list.. No dice.


I'm sure I could do it manually via the .htaccess file, but before I do that (and before I inquire about doing that), I want to make sure I'm doing everything I should be doing through the Server App.


Any ideas?

Mac mini, OS X Mavericks (10.9)

Posted on Nov 29, 2013 9:28 PM

Reply
10 replies

Nov 30, 2013 12:10 PM in response to jaygatsby1123

Where do the web server logs indicate Apache is looking for the error pages? (Possibly very silly question but having been there myself, is the error page you're using what's actually triggering the 404 that you're looking at?)


FWIW and IMO, Console.app is far better at viewing the logs — short of using direct access to the files via less or zcat or grep — than is the Server.app log viewer.


When you've made the changes via Server.app, have you grep'd the configuration files to see where the settings were stored, or tried viewing the settings via the command line? Here's how this works, if you haven't sorted these details already...


At the lower level, the settings are stored in a plist and are accessed based on commands similar to this:


$ sudo serveradmin settings web


Using a "canary" string (xyzzy) as a target, here's where the error page is saved in the configuration data:


web:defaultSite:errorDocuments:500 = "/xyzzy.html"


I'd tend to expect this error page file would need to be relative to the root of the particular site.


The following is from some testing with the canary using the default site:


$ grep -R -i xyzzy /library/server/web

/library/server/web/Config/apache2/sites/0000_any_80_.conf: ErrorDocument 500 /xyzzy.html

Nov 30, 2013 3:04 PM in response to jaygatsby1123

The testing I performed before posting that was live, with no reboots involved, and with the web server running.


When looking for the "canary" amid the configuration plist data:


sudo serveradmin settings web | grep -i xyzzy


The recursive grep through the web server directories for the configuration file changes was shown.


I'd wonder if there's something else going on here.


There is my old favorite harmless diagnostic test for DNS services and local network weirdness, and then an Apache configuration file test for this case:


sudo changeip -checkhostname

apachectl configtest

Dec 1, 2013 6:41 AM in response to jaygatsby1123

Check your host name via the command, and test your Apache configuration, Launch Terminal.app and test your local DNS services and local network weirdness, and test your Apache configuration file syntax:


sudo changeip -checkhostname

apachectl configtest


That'll get a baseline for the common errors. Make sure you're not in .local for your server DNS domain.


Then go read your Apache logs. See if there are any errors being logged there.


If you're not seeing any the entries in the plist file that correspond to changes you have made, then I'd try rebooting and see if that unsnarls Server.app. Next up is probably resetting and reloading Server.app, on the off chance something has gotten corrupted.

Dec 1, 2013 10:31 AM in response to jaygatsby1123

I'll assume those two commands reported no changes required, and that the syntax was OK.


Just realized I might need to repoint the configtest tool, as the files moved and Server.app doesn't use the copy that's in the default location:

$ apachectl -f /library/server/web/config/apache2/httpd_server_app.conf -t


Above is the same configtest, with the path specified.


Details:

cat /library/server/web/config/apache2/readme.txt


The command-line command used to change the settings is the same as used to list it: serveradmin. That's the path into the various plist files. For details on that command, use:


man serveradmin


The Apache configuration stuff is all underneath the directory:


/library/server/web/Config/apache2/


but that shouldn't need to be edited directly, based on what I've seen with Server.app. When it's working, of course.

Dec 1, 2013 6:59 PM in response to jaygatsby1123

Hmmm... Now that I think about it, the "Custom Error Page" defined in Advanced Settings for any given website prefills the "specify path" box with "/500.html", not 404.html... So it probably is working, but it seems to me it would make more sense for them to provide an option for 404, not 500... Whatever, I can still change the 404 page via Apache's config files... Off to Google!

Dec 1, 2013 7:11 PM in response to jaygatsby1123

Okay, I ended up creating and using a .htaccess file to override Apache's default settings, since I had issues saving changes to the .conf files in Library/Server/Web/Config/apache2, it's very locked down, and for good reason of course.


For those with the same issue,


0.5) In OS X Server app's Website settings, click "Advanced Settings" and check the "allow overrides using .htaccess files" box.


1) Create a new document in your favorite text editor. I used TextWrangler, free from the App Store.


2) Copy the text


ErrorDocument 404 /pathtofile


and change /pathtofile to the path to your custom 404 page, which can be HTML or PHP.


3) Save the file as ".htaccess" ideally into the root of your website folder directly, because the dot at the beginning makes it hidden, so you can't save it to the desktop and move it later (unless you show hidden files via that Terminal command)


4) Done! You don't have to restart Apache or OS X Server or OS X for the change to take effect, just go to yoursite.com/someRandomURLthatDoesn'tExist and watch the magic.



Courtesy of http://askubuntu.com/questions/53199/custom-apache-404-page and Google.

This thread has been closed by the system or the community team. You may vote for any posts you find helpful, or search the Community for additional answers.

Having issues setting custom 404 page...

Welcome to Apple Support Community
A forum where Apple customers help each other with their products. Get started with your Apple Account.