CodeIgniter Forums

Full Version: HELP:redirect function works on localhost, but not on live server
You're currently viewing a stripped down version of our content. View the full version with proper formatting.

El Forum

I worked with Codeigniter to build a website that works on localhost, but not completely on a live server. The part that doesn't work should redirect you to a page, but it doesn't. It shows a blank page.
Please help!

El Forum

As you may know, the Codeigniter URL helper redirect has an almost identical counterpart in PHP called header.

Try using the PHP function with the following syntax:
header ('Location:');

The location should be a complete URL with http and www and everything.

If it still doesn't work, I think that might have something to do with the live server's .htaccess file.

If it does work, did you copy the CI system from local to live server too or did you install CI fresh on the live server? Either way, you possibly need to change a configuration setting.

El Forum

the header function didn't work. I think you might be right about the .htaccess file. What do I do? And about the CI system, I just downloaded Codeigniter and then change the name of this folder to the name of my project, and finally, I uploaded the folder to the server.

El Forum

Ok, try using the PHP header function to redirect to some random website like Amazon or Yahoo. If that works but redirect to your own application don't work, that is strong evidence that the problem is in your Codeigniter configuration.

Let's go over the installation steps. On your local server and your live server, you have a web document root directory. If you're running Apache on your PC, that's called htdocs, and if you have the standard $5-8 dollar hosting, that's usually called public_html or var_www or something like that.

In your web document root, you create a directory with your application name. Suppose it's called eshop, so that your visitors can shop at Now you unzip your or whatever version into your eshop directory.

Now you have a directory tree like this
        + eshop:cheese:
            + index.php
            + application
            + system
            + license.txt
            + user_guide

In your eshop directory, you can delete license.txt and user_guide. Now you should add a file called .htaccess to your eshop directory. That file should contain:
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php/$1 [L]

If you don't have this file, you will have to specify the index.php file in every URL. Instead of you would have to have

This may be why your redirects are not working. Can you otherwise navigate your application with no problem?

But anyway, continuing... now upload your actual application files, the ones in your local application directory, to the eshop/application directory. You should never change anything in eshop/system, but there are changes to configure in eshop/application/config. At least you will have to change files

and possibly

Regarding redirection, the issue is most likely in the routes.php file.

I hope this info helps you. Let us know how it goes. Good luck!:cheese:

P.S. Check out the new official Codeigniter forums at

El Forum

I had follow all those steps before, but I noticed that the .htaccess that I had is a little bit different. And there's also another one outside the httdocs folder of the live server. I erased that one, but it still doesn't work.

El Forum

Hmmm, well, let's see... you say you get a blank page when you try to redirect. But does the URL in the browser change to the URL you're trying to go to? If yes, that sounds like there's on error on the page you're trying to go to. Does that page work ok if you access it directly?

A blank page usually means there's an error on the page and that the error display setting is set low enough not to report it. But your server should have a PHP error log where you can see what error was generated.

Can you control the error reporting? Is this a server on shared hosting (cheap monthly charge) or is it a private server in a company?