Force Files to Download and Not Open in Browser Using Apache or PHP

By default most of the file types (eg: pdf, csv, txt, mp3, mov, mp4, jpg, png, gif, html, etc.) displayed in browser instead of download. But we can force browser to download these files instead of showing them. In this article we will explain how to force file download using either Apache or PHP.

Continue reading Force Files to Download and Not Open in Browser Using Apache or PHP


PHP Error Handling using ini_set or .htaccess

Tracking your site’s PHP errors is an excellent way to manage and troubleshoot unexpected issues related to plugins and themes. While there is no definitive method for handling errors, there are some "best practices" that should be implemented in all PHP applications.

An "error" is an expected or unexpected event that occurs when your PHP code is running. An "expected" error can be a database query that returns no result or an html form that is missing values for designated required fields. An "unexpected" error is one that assumes a particular application state which, for some as yet unknown reason, does not exist. The most obvious unexpected error is a database that is not running or a missing file that one of your scripts expects to find.

Continue reading PHP Error Handling using ini_set or .htaccess


How To: Fix WordPress 404 Errors on Password Protected Directories

Using WordPress’s permalink feature seems to cause some issues with password protected directories that use Apache’s .htaccess to handle authentication. I recently had to troubleshoot why after installing WordPress on the root level of the domain that a password protected directory would return a 404 page instead of the typical login box.

The problem comes from the Apache rewrite engine that WordPress uses to make search engine friendly URL’s. WordPress uses a .htaccess file in the root folder of the install to take any URL and allow WordPress to process and serve the appropriate page, or error.

Continue reading How To: Fix WordPress 404 Errors on Password Protected Directories


Creating Search Engine Friendly URLs With Apache and PHP

Utilizing URLs on your site that are search engine friendly is simple and easy to do thanks to PHP and Apache. We will be utilizing permalinks that get rid of all the nasty $_GET data that trails the end of most PHP scripts. An example of a SEO unfriendly URL we will clean is:

http://www.myguysolutions.com/article.php?id=123&title=seo-php-url

Using a combination of Apache’s ForceType directive, the PHP explode() function and PHP’s PATH_INFO variable we can easily turn the sample URL into:

http://www.myguysolutions.com/article/123/seo-php-url

This not only helps our website’s SEO (search engine optimization), but also accomplishes a security concept is known as “security by obscurity”. By obscuring the fact that our web site is using a PHP script, we may detract potential hackers from looking for exploits within our scripts.

Continue reading Creating Search Engine Friendly URLs With Apache and PHP


How To Create a Custom 404 File Not Found Page

One major design element often overlooked by web developers is their 404 File Not Found error page. Most our focus gets lost on CSS and XHTML validation that we often overlook what happens when something goes wrong. Even these pages should be styled with the individual touches of the website. Effective 404 error pages communicate why a particular page couldn’t be displayed and what users can do next.

Who wants their users to see the dreaded default 404 page:

Creating your own custom 404 File Not Found Page can be done in three simple steps by creating or modifying the .htaccess file of the directory and placing a 404.html file in the same directory.

Continue reading How To Create a Custom 404 File Not Found Page