2

I'm trying to access CodeIgniter URLs without 'index.php'. Here's the steps I've taken:

  1. Checked mod_rewrite is enabled - I set a rule to redirect all requests to google, which worked. Also checked that 'AllowOverride All' was set

  2. Added an .htaccess file with the following:

    RewriteEngine On
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteRule ^(.*)$ index.php/$1 [L]
    
  3. Set my directory structure on the webserver as follows:

    /home/wwwsunde/
    -> application
    -> system
    -> public_html
        -> index.php
        -> .htaccess
    
  4. Updated my application/config files so that the system and application paths are '../system' and '../application'

  5. Try to access the site from 2 URLs

    http://109.234.194.207/~wwwsunde/index.php/welcome/membership WORKS
    http://109.234.194.207/~wwwsunde/welcome/membership DOES NOT WORK
    
  6. I've also set CodeIgniter's index page variable to blank as per the guide

The error message shown:

The requested URL /home/wwwsunde/public_html/index.php/welcome/membership was not found on this server.

I'm out of ideas as to what could be wrong - it's an Apache or server issue but I'm not sure what...

6
  • index.php is a directory, not a file? Commented Feb 20, 2012 at 21:19
  • Did you try the instructions at codeigniter.com/wiki/mod_rewrite ? Commented Feb 20, 2012 at 21:21
  • I've been at this for about an hour now, with no success, including that site Commented Feb 20, 2012 at 21:26
  • Have you checked the official CI Documentation? codeigniter.com/user_guide Commented Feb 20, 2012 at 21:35
  • I've taken a look there - the main points seem to be set your application and system paths, leave the index page config var blank in config.php, set .htaccess rewrite rules. The rewriting seems to be working (as you can see from the 404 message The requested URL /home/wwwsunde/public_html/index.php/welcome/membership was not found on this server.). That path (from public_html) works if put into a web browser (i.e. http://109.234.194.207/~wwwsunde/index.php/welcome/membership). But for some reasons it's not being routed right. Commented Feb 20, 2012 at 21:37

2 Answers 2

3

Oh... I know why... make this your rewrite rule:

RewriteRule .* index.php/$0 [PT]

The [L] you had was just a 'last rule' but wouldn't do the quit rewrite you want to quietly handle the background shell game. It would be an endless loop. If this doesn't work, specify the full URL in the rewrite like:

 RewriteRule .* http://109.234.194.207/~wwwsunde/index.php/$0  [PT]
Sign up to request clarification or add additional context in comments.

7 Comments

The 404 path changed to: /home/wwwsunde/public_html/~wwwsunde/index.php/welcome/membership
@codinghands ah, to confirm your document root is public_html and your server name is 109.234.194.207/~wwwsunde/ like if you're using a shared desktop apache on a mac or something
yeah, document root is public_html, server is '109.234.194.207/~wwwsunde' (in config base_url). Server is a VPS with WHM/cPanel installed.
I'm afraid not, the path now is /home/wwwsunde/public_html/index.php/welcome/membership. Which should be correct, because that's the path used (after public_html) I use to access the working version :(
|
1

Where did you get that the index page should be blank? Do you mean index.php? It should be something like this:

<?php
/*
|---------------------------------------------------------------
| PHP ERROR REPORTING LEVEL
|---------------------------------------------------------------
|
| By default CI runs with error reporting set to ALL.  For security
| reasons you are encouraged to change this when your site goes live.
| For more info visit:  http://www.php.net/error_reporting
|
*/
        error_reporting(0);
//      ini_set("display_errors", "on");

/*
|---------------------------------------------------------------
| SYSTEM FOLDER NAME
|---------------------------------------------------------------
|
| This variable must contain the name of your "system" folder.
| Include the path if the folder is not in the same  directory
| as this file.
|
| NO TRAILING SLASH!
|
*/
        $system_folder = "system";

/*
|---------------------------------------------------------------
| APPLICATION FOLDER NAME
|---------------------------------------------------------------
|
| If you want this front controller to use a different "application"
| folder then the default one you can set its name here. The folder
| can also be renamed or relocated anywhere on your server.
| For more info please see the user guide:
| http://codeigniter.com/user_guide/general/managing_apps.html
|
|
| NO TRAILING SLASH!
|
*/
        $application_folder = "application";

/*
|===============================================================
| END OF USER CONFIGURABLE SETTINGS
|===============================================================
*/


/*
|---------------------------------------------------------------
| SET THE SERVER PATH
|---------------------------------------------------------------
|
| Let's attempt to determine the full-server path to the "system"
| folder in order to reduce the possibility of path problems.
| Note: We only attempt this if the user hasn't specified a
| full server path.
|
*/
if (strpos($system_folder, '/') === FALSE)
{
        if (function_exists('realpath') AND @realpath(dirname(__FILE__)) !== FALSE)
        {
                $system_folder = realpath(dirname(__FILE__)).'/'.$system_folder;
        }
}
else
{
        // Swap directory separators to Unix style for consistency
        $system_folder = str_replace("\\", "/", $system_folder);
}

/*
|---------------------------------------------------------------
| DEFINE APPLICATION CONSTANTS
|---------------------------------------------------------------
|
| EXT           - The file extension.  Typically ".php"
| FCPATH        - The full server path to THIS file
| SELF          - The name of THIS file (typically "index.php")
| BASEPATH      - The full server path to the "system" folder
| APPPATH       - The full server path to the "application" folder
| MEDIAPATH - The full server path to the "media" folder
*/
define('EXT', '.'.pathinfo(__FILE__, PATHINFO_EXTENSION));
define('FCPATH', __FILE__);
define('SELF', pathinfo(__FILE__, PATHINFO_BASENAME));
define('BASEPATH', $system_folder.'/');
define('MEDIAPATH', dirname(__FILE__).'/media');

if (is_dir($application_folder))
{
        define('APPPATH', $application_folder.'/');
}
else
{
        if ($application_folder == '')
        {
                $application_folder = 'application';
        }

        define('APPPATH', BASEPATH.$application_folder.'/');
}

/*
|---------------------------------------------------------------
| LOAD THE FRONT CONTROLLER
|---------------------------------------------------------------
|
| And away we go...
|
*/
require_once BASEPATH.'codeigniter/CodeIgniter'.EXT;

/* End of file index.php */
/* Location: ./index.php */

Mind you I randomly grabbed this from one of our CI projects so it might be customized - I don't really remember - but it is definitely not blank.

Also, the config:

$config['uri_protocol']="REQUEST_URI"; 

and htaccess:

<IfModule mod_rewrite.c>
    RewriteEngine On
    RewriteBase /

    RewriteCond %{REQUEST_URI} ^system.*
    RewriteRule ^(.*)$ /index.php?/$1 [L]

    RewriteCond %{REQUEST_URI} ^application.*
    RewriteRule ^(.*)$ /index.php?/$1 [L]

    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteRule ^(.*)$ index.php?/$1 [L]
</IfModule>

2 Comments

I should of said 'indexpage' variable, not the actual index.php. I've set my system and application folder paths there.
fair enough - my post is probably useless in its entirety then. Sorry.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.