Tag Archives: .htaccess

Increase PHP’s File Upload Settings with .htaccess

From time to time the need comes up to increase the maximum file upload size for a website. For reference, what I’m referring to is uploading media files (pictures, PDFs, data files, etc.) through an HTML web form.

Typically PHP comes configured to allow a 2 Meg upload size. Some web hosting companies allow you to make these changes directly in the PHP.ini file. In that case you open your PHP.ini file and simply look for “upload_max_filesize”, “post_max_size”, and “memory_limit” and make the appropriate changes.

If no PHP.ini file is available through your hosting platform an alternative method for adjusting this would be to add the following three lines to your .htaccess file.

php_value  upload_max_filesize  8M
php_value  post_max_size  16M
php_value  memory_limit  24M 

Some notes:

Keep in mind that extra large files will take longer to upload so you’ll want to make sure that your scripts do not time out when uploading. This will be a trial-and-error process based most likely on your client’s Internet connection speeds.

URL Trailing Slashes and Canonical URLs

I noticed recently in my Google Webmaster Tools account that Google seems to be honing in on house cleaning for webmasters. Maybe it’s the recent Google updates that have come down the pike in the past twelve months and maybe it’s just my imagination but nonetheless it’s a good habit for webmasters to practice.

The one thing that lead my suspicion of this was the notes on a few of my sites that Google has begun to put into “HTML Improvements area is alerts over trailing slashes in the URL string. For reference, the following URLs are not the same to a search engine:

  1. http://www.mysite.com/page-name
  2. http://www.mysite.com/page-name/
  3. http://www.mysite.com/page-name/index.html

Because I generally don’t link to any index.html files directly inside of directories, the first two in the list were of particular concern to me and not the third.

The solution is to put the following three lines into your .htaccess file:

RewriteCond %{REQUEST_URI} !\.[^./]+$
RewriteCond %{REQUEST_URI} !(.*)/$
RewriteRule ^(.*)$ http://www.mysite.com/$1/ [R=301,L]

That will automatically enter the trailing slash to the url if it is not already present. Remember to keep those three lines together in the .htaccess file.

Running PHP Script Inside of .HTM and .HTML Files

If your site is running on a LAMP (Linux, Apache, MySQL, PHP) platform it is possible to make the server execute PHP scripts inside of a .HTM or .HTML page.  Pages with the HTML file extensions (.htm or .html) typically, when requested from the server are just sent straight to the browser by the server. With those extensions the web server assumes that there is nothing more to do than that. With Apache’s .htaccess file, however, you can alter this.

Why would you want to do that? It is common for webmasters to come across situations where a site consists entirely of static HTML files and the job does not allow for changing those extensions. Typically this is for search engine reasons.

The quick work-around for this is to add a line or to into the .htaccess file in the site’s root directory that will tell the server to look through each .html or .htm files for PHP scripting prior to sending them to the requesting browser/user. The exact lines of .htaccess code will depending upon the settings of the server that you’re running on but here are the most common.

AddHandler php-script .htm .html


AddType application/x-httpd-php .php .htm .html

Each simply tells the server to parse HTML pages as if they were PHP pages and generally, one of those two lines will accomplish the goal.

.HTACCESS File Resource

Here is a nice resource for common questions regarding Apache’s .htaccess file. The file can be used for supplemental PHP and general website config settings on sites that are running on Apache web server.

Link: www.htaccesstools.com

Topics include:

  • Htpasswd Generator
  • Htaccess Authentication
  • Prevent hotlinking of images
  • Block IPs with .htaccess
  • Block hitbots with .htaccess
  • Error Document
  • Redirection by Language