Page 1 of 1

[Solved] Custom error pages - 401, 403 and 404

Posted: Wed Mar 19, 2008 1:19 am
by nwcon
I've been through the forum searching for others who might have already accomplished this, but I haven't found what I'm looking for.  Google search didn't offer up anything useful either.

With my previous website, all static content, I used the apache ErrorDocument directive to serve custom error pages for 401, 403, and 404 errors.  I found the custom 404 error message setting in cmsms, but it doesn't seem to work reliably.  In addition, I have not found a way to simulate the 401 and 403 error messages.

First question: Is there a howto or FAQ detailing the usage and proper setup/configuration for using the custom 404 error message in cmsms?  I can't seem to get it to work consistently.  Is it something to do with mod_rewrite and options in the config.php for clean URLs?

Second question:  How would I go about implementing custom 401 and 403 error pages?  Has anyone information on doing this?  Or is there an easier way...maybe just creating static error files (e.g. 401.html) that use the same css as my cmsms pages use?

I'm using CMSMS 1.2.3 under linux.

Regards,

nwcon

Re: Custom error pages - 401, 403 and 404

Posted: Wed Mar 19, 2008 1:32 am
by nwcon
Okay.  If I would have actually _tried_ the section in the Tips and Tricks/Installation for Pretty URLs, I would have realized it did what I wanted...mostly.  I can live with the results.

I'll keep digging for an answer on how to implement custom 401 and 403 error pages in cmsms like apache implements them.

Regards,

nwcon

Re: Custom error pages - 401, 403 and 404

Posted: Wed Mar 19, 2008 2:11 am
by nwcon
Okay, I'm sorry to have bothered the list, but maybe someone else can benefit from this.

I have a working setup for any custom error page one might need.

After getting Pretty URLs working per the Tips and Tricks/Installation page and making suggested changes in my config.php, I set apache to use custom error pages for 401, 403 and 404 as follows:

Apache config
ErrorDocument 401 /cmsms/error-401.html
ErrorDocument 403 /cmsms/error-403.html
ErrorDocument 404 /cmsms/error-404.html

Then I created Pages in cmsms for each and titled them as "Error 401", "Error 403" and "Error 404".  These pages have the option deselected for showing in menu i.e. they don't show up in the website's menu.  Thus, when and Error 401 occurs, the URL served to the client is http://www.example.com/cmsms/error-401.html, and this is how apache now redirects errors to cmsms.

Hope this helps some other poor sap like me!

Regards,

nwcon

Re: Custom error pages - 401, 403 and 404

Posted: Wed Mar 19, 2008 9:29 pm
by Pierre M.
Hello,

thank you for sharing this.
Please consider publishing it in the wiki along with the other tips you have found.

Pierre M.

Re: Custom error pages - 401, 403 and 404

Posted: Tue Apr 22, 2008 3:08 pm
by nidus
Hi nwcon,
can you explain what you have in .htaccess to make it work?
I have in apache config:
ErrorDocument 404 /404page.html

calling direct /404page.html works, it goes to 404page created in the cms admin, but any none existing pages called do not go there. It seams to me as .httaccess problem, here what I have:

Options +FollowSymLinks
ServerSignature Off

RewriteEngine on
RewriteBase /

# URL Filtering helps stop some hack attempts
#IF the URI contains a "http:"
RewriteCond %{QUERY_STRING} http\: [OR]
#OR if the URI contains a "["
RewriteCond %{QUERY_STRING} \[ [OR]
#OR if the URI contains a "]"
RewriteCond %{QUERY_STRING} \] [OR]
#OR if the URI contains a ""
RewriteCond %{QUERY_STRING} (\|%3E) [NC,OR]
#OR script trying to set a PHP GLOBALS variable via URL
RewriteCond %{QUERY_STRING} GLOBALS(=|\[|\%[0-9A-Z]{0,2}) [OR]
#OR any script trying to modify a _REQUEST variable via URL
RewriteCond %{QUERY_STRING} _REQUEST(=|\[|\%[0-9A-Z]{0,2})
RewriteRule ^.*$ - [F,L]
# END Filtering

RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.+)(.html)?$ index.php?p=$1 [QSA]

Any suggestions?

Re: Custom error pages - 401, 403 and 404

Posted: Tue May 06, 2008 9:16 pm
by nwcon
Sorry for the delay.  I will add my setup to the Wiki as soon as possible.

But for a quick answer, I have the following in my apache.conf for my cmsms dir

        Options -Indexes +FollowSymLinks
        Order allow,deny
        Allow from All
        RewriteEngine on

        # 301 Redirect all requests that don't contain a dot or trailing slash to
        # include a trailing slash
        RewriteCond %{REQUEST_URI} !/$
        RewriteCond %{REQUEST_URI} !\.
        RewriteRule ^(.*) %{REQUEST_URI}/ [R=301,L]

        # Rewrites urls in the form of /parent/child/
        # but only rewrites if the requested URL is not a file or directory
        RewriteCond %{REQUEST_FILENAME} !-f
        RewriteCond %{REQUEST_FILENAME} !-d
        RewriteRule ^(.+)$ index.php?page=$1 [QSA]


Regards,

nwcon

Re: Custom error pages - 401, 403 and 404

Posted: Tue May 06, 2008 11:02 pm
by nwcon
Just added a Wiki on my setup for custom error pages.  Its under Tips and Tricks.

Feel free to ask questions or point out errors  ;D

Regards,

nwcon

Re: [Solved] Custom error pages - 401, 403 and 404

Posted: Tue May 13, 2008 10:20 pm
by nickf
Hello nwcon,

Thank you for the post and for the wiki.

The host will not provide me with access to apache.conf or httpd.conf so my only options are through htaccess (or php.ini which is what they suggest).

Have you any ideas how to make custom error pages work when without editing apache.conf or httpd.conf?


eg: where to put this?

        Options -Indexes +FollowSymLinks
        Order allow,deny
        Allow from All
        RewriteEngine on

        # 301 Redirect all requests that don't contain a dot or trailing slash to
        # include a trailing slash
        RewriteCond %{REQUEST_URI} !/$
        RewriteCond %{REQUEST_URI} !\.
        RewriteRule ^(.*) %{REQUEST_URI}/ [R=301,L]

        # Rewrites urls in the form of /parent/child/
        # but only rewrites if the requested URL is not a file or directory
        RewriteCond %{REQUEST_FILENAME} !-f
        RewriteCond %{REQUEST_FILENAME} !-d
        RewriteRule ^(.+)$ index.php?page=$1 [QSA]


I have this is in config.php:
$config['assume_mod_rewrite'] = true;
$config['page_extension'] = '.php';
$config['internal_pretty_urls'] = false;
$config['use_hierarchy'] = true;

This is driving me crazy - custom error pages are so easy with a static site - this is way more complicated that it needs to be. I don't understand why cmsms can't do all the error pages (rather than just the 404 option).

Thanks so much for your help.