 {"id":381831,"date":"2023-01-09T08:28:03","date_gmt":"2023-01-09T15:28:03","guid":{"rendered":"https:\/\/jorgep.com\/blog\/?page_id=381831"},"modified":"2023-01-09T13:55:39","modified_gmt":"2023-01-09T20:55:39","slug":"404handler","status":"publish","type":"page","link":"https:\/\/jorgep.com\/blog\/404handler\/","title":{"rendered":"404Handler"},"content":{"rendered":"\n<p>Often times I need to place a way to handle short links on sites that manage.   Many of the ones out there have many features I do not need and or require significant effort to implement.  I needed something quick and simple and could not find one that I liked.  I decided to write one. <\/p>\n\n\n\n<figure class=\"wp-block-image size-full\"><a href=\"https:\/\/jorgep.com\/blog\/wp-content\/uploads\/2023\/01\/image-2.png\"><img loading=\"lazy\" decoding=\"async\" width=\"873\" height=\"553\" src=\"https:\/\/jorgep.com\/blog\/wp-content\/uploads\/2023\/01\/image-2.png\" alt=\"\" class=\"wp-image-381918\" srcset=\"https:\/\/jorgep.com\/blog\/wp-content\/uploads\/2023\/01\/image-2.png 873w, https:\/\/jorgep.com\/blog\/wp-content\/uploads\/2023\/01\/image-2-300x190.png 300w, https:\/\/jorgep.com\/blog\/wp-content\/uploads\/2023\/01\/image-2-768x486.png 768w\" sizes=\"auto, (max-width: 873px) 100vw, 873px\" \/><\/a><\/figure>\n\n\n\n<h2 class=\"wp-block-heading\">Features<\/h2>\n\n\n\n<ul class=\"wp-block-list\">\n<li>shortlinks are stored in MyQL database<\/li>\n\n\n\n<li>Admin Panel interface<\/li>\n\n\n\n<li>create a log file of all requests handled ( 404 errors)<\/li>\n<\/ul>\n\n\n\n<p>This PHP-based script handles shortlinks for websites based on data placed on a mySQL database.  It also has a way to manage (add, change, delete) entries via a simple admin page. <\/p>\n\n\n\n<p>It was important to me that the program fit within an existing site with minimal impact ( thus the need to only modify .htaccess and include 4 files. The app handles 404 requests and records to a log file so I can check what is being requested<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Sample demo site: <a rel=\"noreferrer noopener\" href=\"https:\/\/404handlerdemo.jorgep.com\/\" target=\"_blank\">https:\/\/404handlerdemo.jorgep.com\/<\/a><\/h2>\n\n\n\n<h2 class=\"wp-block-heading\">Requirements<\/h2>\n\n\n\n<ul class=\"wp-block-list\">\n<li>Access to a MySQL database server ( Script  will create the table if not already there, but needs the DB credentials )<\/li>\n\n\n\n<li>php v5.7 or better.<\/li>\n<\/ul>\n\n\n\n<h2 class=\"wp-block-heading\">Core Files:<\/h2>\n\n\n\n<p>404handler.php            \/\/ core front-end shortlink handler<br>404appLanding.html   \/\/ landing page when a shortlink is not found. ( can be modified in 404appConfigPROD.php file)<br>404appConfigPROD.php \/\/ configuration file (database creds and other variables)<br>404appFunctions.php   \/\/ common PHP functions files<br>404appAdmin.php      \/\/ admin interface to add\/edit\/delete db records<\/p>\n\n\n\n<p><strong><em>Additional supporting<\/em><\/strong> (not needed for operatios) &#8230;. )<br>read.md \/\/ Readme file<br>404appConfig-SAMPLE.php \/\/ SAMPLE configuration file<br>404appSample-htaccess.txt \/\/ SAMPLE .htaccess file<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Installation<\/h2>\n\n\n\n<ul class=\"wp-block-list\">\n<li>download and unzip the latest 404appHandler.zip  to a local directory<\/li>\n\n\n\n<li>copy or rename 404appConfigSAMPLE.php to  404appConfigPROD.php   <\/li>\n\n\n\n<li> Modify setting 404appConfigPROD.php to correct database credentials ( there are other parameters there as well but defaults will work well.)<\/li>\n\n\n\n<li>move the core files to your webserver root directory (via upload pannel or FTP )<\/li>\n\n\n\n<li>Modify .htaccess on root directory file to include the follwing 2 lines:<\/li>\n<\/ul>\n\n\n\n<pre class=\"wp-block-code\"><code>RewriteEngine On\nErrorDocument 404 \/404handler.php<\/code><\/pre>\n\n\n\n<p><\/p>\n\n\n\n<p><\/p>\n\n\n\n<h2 class=\"wp-block-heading\"><\/h2>\n\n\n\n<p><\/p>\n","protected":false},"excerpt":{"rendered":"<p>Often times I need to place a way to handle short links on sites that manage. Many of the ones out there have many features I do not need and or require significant effort to implement. I needed something quick and simple and could not find one that I liked. I decided to write one&#8230;.<\/p>\n","protected":false},"author":2,"featured_media":381918,"parent":0,"menu_order":0,"comment_status":"closed","ping_status":"closed","template":"","meta":{"_kad_blocks_custom_css":"","_kad_blocks_head_custom_js":"","_kad_blocks_body_custom_js":"","_kad_blocks_footer_custom_js":"","ngg_post_thumbnail":0,"_kad_post_transparent":"","_kad_post_title":"","_kad_post_layout":"","_kad_post_sidebar_id":"","_kad_post_content_style":"","_kad_post_vertical_padding":"","_kad_post_feature":"","_kad_post_feature_position":"","_kad_post_header":false,"_kad_post_footer":false,"_kad_post_classname":"","footnotes":""},"class_list":["post-381831","page","type-page","status-publish","has-post-thumbnail","hentry"],"taxonomy_info":[],"featured_image_src_large":["https:\/\/jorgep.com\/blog\/wp-content\/uploads\/2023\/01\/image-2.png",873,553,false],"author_info":{"display_name":"Jorge Pereira","author_link":"https:\/\/jorgep.com\/blog\/author\/jorge\/"},"comment_info":0,"_links":{"self":[{"href":"https:\/\/jorgep.com\/blog\/wp-json\/wp\/v2\/pages\/381831","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/jorgep.com\/blog\/wp-json\/wp\/v2\/pages"}],"about":[{"href":"https:\/\/jorgep.com\/blog\/wp-json\/wp\/v2\/types\/page"}],"author":[{"embeddable":true,"href":"https:\/\/jorgep.com\/blog\/wp-json\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/jorgep.com\/blog\/wp-json\/wp\/v2\/comments?post=381831"}],"version-history":[{"count":0,"href":"https:\/\/jorgep.com\/blog\/wp-json\/wp\/v2\/pages\/381831\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/jorgep.com\/blog\/wp-json\/wp\/v2\/media\/381918"}],"wp:attachment":[{"href":"https:\/\/jorgep.com\/blog\/wp-json\/wp\/v2\/media?parent=381831"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}