Setup a redirect in a store template using PHP
  Last Edited - 01/6/2015 2:43pm PST
  Category Path - Shopping Cart Software Components
How can I force my store's home page to redirect straight to the checkout page instead? I use the store's "Add to Cart" links on my other website, and only need the customer to get to the checkout page in my store. Please advise.

This is a fairly easy task to accomplish, and will only require a little bit of PHP code in the template that controls the home page.

please note:
Troubleshooting custom code in templates does fall outside of Modular Merchant's range of free technical support. (Modular Merchant's Spheres of Support is available at:

We're always happy to help when we can, but fixing larger template issues may require paid development time. We evaluate each request on a case-by-case basis. If a request is so large that it requires a custom web design project to resolve, we will always provide a proposal for the client's approval prior to performing any billable work.

To do this, take the following steps:

1. Navigate to [Design > Template Package Sandbox] in your store's Administration Area.

2. Select a Template Package to Edit.

3. If it isn't already, populate the "index.tpl" template into your package. This is done from the Template Package Options row, by clicking Populate Templates. In the popup, select the checkbox for index.tpl, and click Populate Selected Templates.

4. Under Template Package Files, select index.tpl.

5. At the top right of the Template Editor, click Switch to Plain Text Editor. This will switch the editor to show the source code of the template.

6. At the very beginning of the template's source code, paste the following code snippet; replacing the URL with the one you wish to direct visitors to:

code example

header( 'Location:' ) ;



In order to have visitors of index page redirected to checkout, you will want to enter the checkout page of your store as the URL. (Such as

Make sure this code is at the absolute beginning of the template, before any other page content; even before <html> and other such tags. If it is not, the page will not function properly.

7. Under File Options, be sure that "Save" is selected.

8. Click Save Changes.
With this change to the template, customers who visit the index page of the store will now be directed to the checkout page instead.

You're done!

You can do this to any template or webpage on servers running PHP.

Be very careful what templates or pages you decide to setup redirects in, especially the store's universal template: universal.tpl

As an example, if you setup a redirect in universal.tpl, this will result in any templates that aren't populated into your template package redirecting to the specified URL.
Powered by ModularKB