Richard Castera - Explorations in Software Development
Richard Castera - Explorations in Software Development
Browsing Category
Scripts
Resources Scripts Web Server

How to Create a Custom 404 Error page with .htaccess

October 20, 2009 2 Comments

Everyone’s encountered those standard 404 error pages that yield little or no information. Most new systems have this feature built in by default and often times are pretty fancy with informative to funny graphics and lots of options on what to do next but, if your working on updating an old site not using dynamically based web pages then, your going to have to add one manually. For your user’s experience, it’s better to provide a helpful error message and links to where they can continue on their quest for information. You don’t want to scare your visitors away do you? Here’s how to add your own custom 404 error page to your website:

If you don’t already have an .htaccess file in your servers root, go ahead and create one. Now you need to instruct .htaccess where your custom error page is. In this example, I have the 404 document which I created with my editor that provides lots of useful information for users to continue browsing my site. Now add this line to your .htaccess file and that’s it!

Apache
1
ErrorDocument 404 /404.html
Continue reading
Reading time: 1 min
Share:
Written by: rcastera
Resources Scripts Web Server

Disallow hotlinking while allowing requests from robots.txt and favicons

October 18, 2009 No Comments

We all hate Leechers. Here’s how to stop them in their tracks from stealing your images and your bandwidth!

Apache
1
2
3
4
5
6
Options +FollowSymLinks
RewriteEngine on
RewriteCond %{REQUEST_URI} !(^/robots\.txt|\.ico)$
RewriteCond %{HTTP_REFERER} !^$
RewriteCond %{HTTP_REFERER} !^http://(www\.)?example.com(/)?.*$ [NC]
RewriteRule .*\.(gif|jpg|jpeg|bmp|pdf)$ [F,L]
Continue reading
Reading time: 1 min
Share:
Written by: rcastera
Resources Scripts Web Server

htaccess – How to redirect all http (port 80) requests to https (port 443)

September 13, 2009 4 Comments

Sometimes you may need to redirect http requests on port 80 to (https) on port 443. This can easily be accomplished with .htaccess.

Apache
1
2
3
RewriteEngine on
RewriteCond %{SERVER_PORT} !^443$
RewriteRule ^/(.*) https://%{SERVER_NAME}/$1 [NC,R,L]
Continue reading
Reading time: 1 min
Share:
Written by: rcastera
Resources Scripts

Magento – How to run a SQL query against the database

August 23, 2009 7 Comments

In order to run a SQL query against the Magento database, you first need a resource model then a database connection.

PHP
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
<?php
$db = Mage::getResourceSingleton('core/resource')->getConnection('core_write');
$result = $db->query('SELECT 'entity_id' FROM 'catalog_product_entity');
if (!$result) {
    return FALSE;
}
$rows = $result->fetch(PDO::FETCH_ASSOC);
if (!$rows) {
    return FALSE;
}
print_r($rows);
?>
Continue reading
Reading time: 1 min
Share:
Written by: rcastera
Resources Scripts

Magento – Database Repair Tool

August 20, 2009 No Comments

The Magento Database Repair Tool compares 2 databases (reference and target), and updates the target database so it has the same structure as the reference database by doing the following:

  • Adds missing tables, or repairs them to have the same engine type and char-set.
  • Adds missing fields or repairs them.
  • Removes inconsistent data from tables that have broken foreign key references.
  • Adds missing foreign keys and indexes.

You can download it here. For a full list of features and instructions, you can refer to this wiki post.

Continue reading
Reading time: 1 min
Share:
Written by: rcastera
Resources Scripts

Magento – Add additional fields to the Contact Form

August 16, 2009 38 Comments

If you need to add additional fields to Magento’s default contact form, read on! First open the form.phtml file located in your /magento_root/app/design/frontend/YOUR_INTERFACE/YOUR_THEME/template/contacts/form.phtml. So, we are going to add a subject field to this contact form so that customers tell us the subject of their email. Open the file for editing in your favorite editor.

Find this section in the file below (this should be around line 39):

XHTML
1
2
3
4
<div class="input-box">
    <label for="name"><?php echo Mage::helper('contacts')->__('Name') ?> <span class="required">*</span></label>
    <input name="name" id="name" title="<?php echo Mage::helper('contacts')->__('Name') ?>" value="<?php echo $this->htmlEscape($this->helper('contacts')->getUserName()) ?>" class="required-entry input-text" type="text"/>
</div>
Continue reading
Reading time: 2 min
Share:
Written by: rcastera
Resources Scripts Thoughts

Drupal – The Best and my Favorite Modules

August 9, 2009 2 Comments

I’ve worked with Drupal in the past for several projects and have come across some modules that have become my favorites. Here they are:

Continue reading
Reading time: 2 min
Share:
Written by: rcastera
Resources Scripts

Magento – Upgrade to the latest version using Magento Connect

August 4, 2009 9 Comments

Upgrading Magento to the latest version is a fairly simple task. Copy and Paste this key below VIA Magento Connect where it states “Paste extension key to install:”. This will upgrade Magento to the newest version.

XHTML
1
magento-core/Mage_All_Latest
Continue reading
Reading time: 1 min
Share:
Written by: rcastera
Resources Scripts

Magento – Get the Current Category

August 3, 2009 16 Comments

Need to get the current category loaded? No problem! Just use this useful little snippet below. It will return an object of the current category.

PHP
1
<?php $currentCategory = Mage::registry('current_category'); ?>
Continue reading
Reading time: 1 min
Share:
Written by: rcastera
Resources Scripts

Magento – Add a product with custom options to the cart through URL Querystring

August 2, 2009 21 Comments

Magento is truly a powerful and flexible platform! I enjoy working with it more and more every day. I recently came across the need to add a product to the cart VIA the Querystring/URL. Guess what? Magento can do it and I’ll show you how!

Simple products are the easiest to add because there are fewer options that need to be passed. The basic structure is as follows.

XHTML
1
http://www.mydomain.com/checkout/cart/add?product=[id]&qty=[qty]

Where [id] is the Magento ID of the product and [qty] is the Quantity you wish to add.

To add a simple product with custom options simply add options[id]=[value] to the end. The basic structure is:

XHTML
1
http://www.mydomain.com/checkout/cart/add?product=[id]&qty=[qty]&options[id]=[value]

You can get the options id and value by viewing the source of the simple product page and it’s dropdowns.

Continue reading
Reading time: 1 min
Share:
Written by: rcastera
Page 4 of 9« First...«3456»...Last »

About me

Hello, my name is Richard Castera. I have more than 12 years of experience architecting, implementing, leading and launching large scale, high performance software products in a fast-paced agile environment.

Popular Posts

Magento – Display new products on the home page

May 20, 2009

How to Fix “Internet Explorer Cannot Open the Internet Site- Operation Aborted” Error

May 9, 2009

PHP – Convert Array to Object with stdClass

July 5, 2009

Categories

  • Home Automation
  • Resources
  • Scripts
  • SEO
  • Thoughts
  • Web Server

Tags

Apache Apple Bash CSS Drupal Free home automation htaccess Java Javascript Magento PHP raspberry pi SEO SQL thoughts Wordpress

© 2019 copyright Richard Castera // All rights reserved