User Tools

Site Tools


custom_error_pages_for_your_site

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Both sides previous revision Previous revision
Next revision
Previous revision
custom_error_pages_for_your_site [2022/02/13 22:21]
jquah
custom_error_pages_for_your_site [2022/02/13 22:35] (current)
jquah
Line 44: Line 44:
  
 "ErrorDocument" indicates that you are defining your own, "404" is the error code you are taking responsibility for, and ''/404.html'' is the name and location of your custom error document. Please note that the "/" in front of the file name indicates that ''404.html'' may be found in the //www root directory of the site that the server is masquerading as// (a concept known as DOCUMENT_ROOT). Because the same physical computer might handle requests for multiple host names, the DOCUMENT_ROOT will be different for each SDF user's vanity domain. Whenever the original request makes use of a vanity domain, say, //altego.freeshell.org//, the custom error document in the html subdirectory of //altego//'s $HOME will be loaded with the syntax above. "ErrorDocument" indicates that you are defining your own, "404" is the error code you are taking responsibility for, and ''/404.html'' is the name and location of your custom error document. Please note that the "/" in front of the file name indicates that ''404.html'' may be found in the //www root directory of the site that the server is masquerading as// (a concept known as DOCUMENT_ROOT). Because the same physical computer might handle requests for multiple host names, the DOCUMENT_ROOT will be different for each SDF user's vanity domain. Whenever the original request makes use of a vanity domain, say, //altego.freeshell.org//, the custom error document in the html subdirectory of //altego//'s $HOME will be loaded with the syntax above.
 +
 +===== Changes needed if you use Apache's mod_userdir =====
  
 Some SDF users prefer to have their sites accessible via **tilde-style URLs**, like http://sdf.org/~altego . In this case the DOCUMENT_ROOT is no longer pointed at //altego//'s html directory, but instead to the root html directory for SDF as a whole. Hence the location of the custom error page must be modified like so: Some SDF users prefer to have their sites accessible via **tilde-style URLs**, like http://sdf.org/~altego . In this case the DOCUMENT_ROOT is no longer pointed at //altego//'s html directory, but instead to the root html directory for SDF as a whole. Hence the location of the custom error page must be modified like so:
Line 53: Line 55:
 If you want the same custom error page to show up //regardless of whether the visitor types the vanity domain or the tilde-style URL//, it becomes much more difficult for a single .htaccess file to do the job. (RewriteRule directives prefaced by conditions on HTTP_HOST are the most obvious mechanism, but they have to be constructed very carefully in order to play nice with the UserDir settings in httpd.conf. Detailed instructions are beyond the scope of this tutorial.) Choosing just one of the above syntaxes for ~/html/.htaccess will send half your visitors to another nonexistent URL, accompanied by a warning from the SDF server about errors encountered when processing .htaccess! If you want the same custom error page to show up //regardless of whether the visitor types the vanity domain or the tilde-style URL//, it becomes much more difficult for a single .htaccess file to do the job. (RewriteRule directives prefaced by conditions on HTTP_HOST are the most obvious mechanism, but they have to be constructed very carefully in order to play nice with the UserDir settings in httpd.conf. Detailed instructions are beyond the scope of this tutorial.) Choosing just one of the above syntaxes for ~/html/.htaccess will send half your visitors to another nonexistent URL, accompanied by a warning from the SDF server about errors encountered when processing .htaccess!
  
-Here are two possible ways to let your visitors use either style of URL, and still get your customized error page if they make a typo. They both involve duplication of the hosted content and (possibly manual) sync jobs. (To avoid these complications you might choose to: (a) disable the tilde-style URL --- ''mkhomepg -d'' will remove or insert your $LOGNAME in the ''UserDir enabled ...'' directive near the end of httpd.conf, (b) pare down the folder of the less-popular URL to a simple index.html that performs a redirect, or (c) try to hack together a workable combination of RewriteCond and RewriteRule directives that plays nicely with the UserDir settings in httpd.conf.) +Here are two possible ways to let your visitors use either style of URL, and still get your customized error page if they make a typo. They both involve duplication of the hosted content and (possibly manual) sync jobs. (To avoid these complications you might choose to: (a) disable the tilde-style URL --- ''mkhomepg -d'' will remove or insert your $LOGNAME in the ''UserDir enabled ...'' directive near the end of httpd.conf, (b) pare down the folder of the less-popular URL to a simple index.html that performs a redirect, or %%(c)%% try to hack together a workable combination of RewriteCond and RewriteRule directives that plays nicely with the UserDir settings in httpd.conf.) 
-  Delete the public_html symlink created by ''mkhomepg -d'', and make an actual folder of that name in your home directory. Give it and its parent directory loose enough permissions (go+rx should suffice) that the Apache "tilde user" can navigate to it. Periodically synchronize between public_html and html all content EXCEPT the .htaccess file, and make sure each folder's .htaccess gives the correct location relative to the DOCUMENT_ROOT (~/html/.htaccess contains ''ErrorDocument 404 /404.html'', while ~/public_html/.htaccess contains ''ErrorDocument 404 /~altego/404.html''). +  * **Option 1:** Delete the public_html symlink created by ''mkhomepg -d'', and make an actual folder of that name in your home directory. Give it and its parent directory loose enough permissions (go+rx should suffice) that the Apache "tilde user" can navigate to it. Periodically synchronize between public_html and html all content EXCEPT the .htaccess file, and make sure each folder's .htaccess gives the correct location relative to the DOCUMENT_ROOT (~/html/.htaccess contains ''ErrorDocument 404 /404.html'', while ~/public_html/.htaccess looks like ''ErrorDocument 404 /~altego/404.html''). 
-  Upgrade your membership to MetaARPA and toggle vanity domain hosting to the MetaArray. The tilde-style URL will still resolve to the cluster, where ''ErrorDocument 404 /~altego/404.html'' will continue to work as before. The vanity domain will resolve to mab, where your content must be uploaded again into the appropriate directory, and the htaccess file modified to read ''ErrorDocument 404 /404.html''. With MetaARPA membership you can set up a cronjob to keep the contents of your two html directories (cluster and MetaArray) in sync.+  * **Option 2:** Upgrade your membership to MetaARPA and toggle vanity domain hosting to the MetaArray. The tilde-style URL will still resolve to the cluster, where ''ErrorDocument 404 /~altego/404.html'' will continue to work as before. The vanity domain will resolve to mab, where your content must be uploaded again into the appropriate directory, and the htaccess file modified to read ''ErrorDocument 404 /404.html''. With MetaARPA membership you can set up a cronjob to keep the contents of your two html directories (cluster and MetaArray) in sync. 
 + 
 +===== Other changes you might need =====
  
-Of course, if you place the document in a subdirectory off your html root, you need to indicate that path in ".htaccess". If you are creating custom pages for additional codes, simply add the appropriate lines in ".htaccess".+If you place the document in a subdirectory off your html root, you need to indicate that path in ".htaccess". If you are creating custom pages for additional codes, simply add the appropriate lines in ".htaccess".
  
 After making your changes, it may be a good idea to reset the permissions on your website by entering the command: After making your changes, it may be a good idea to reset the permissions on your website by entering the command:
custom_error_pages_for_your_site.1644790910.txt.gz · Last modified: 2022/02/13 22:21 by jquah