CodeIgniter Forums
Problems routing index.php when running CI within a folder - Printable Version

+- CodeIgniter Forums (https://forum.codeigniter.com)
+-- Forum: Archived Discussions (https://forum.codeigniter.com/forum-20.html)
+--- Forum: Archived Development & Programming (https://forum.codeigniter.com/forum-23.html)
+--- Thread: Problems routing index.php when running CI within a folder (/thread-33961.html)



Problems routing index.php when running CI within a folder - El Forum - 09-14-2010

[eluser]brettalton[/eluser]
I'm having trouble re-routing and making index.php disappear when I'm running CI within a folder.

.htaccess from wiki:

Code:
<IfModule mod_rewrite.c>
    RewriteEngine On
    RewriteBase /

    #Removes access to the system folder by users.
    #Additionally this will allow you to create a System.php controller,
    #previously this would not have been possible.
    #'system' can be replaced if you have renamed your system folder.
    RewriteCond %{REQUEST_URI} ^system.*
    RewriteRule ^(.*)$ /index.php?/$1 [L]
    
    #When your application folder isn't in the system folder
    #This snippet prevents user access to the application folder
    #Submitted by: Fabdrol
    #Rename 'application' to your applications folder name.
    RewriteCond %{REQUEST_URI} ^application.*
    RewriteRule ^(.*)$ /index.php?/$1 [L]

    #Checks to see if the user is attempting to access a valid file,
    #such as an image or css document, if this isn't true it sends the
    #request to index.php
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteRule ^(.*)$ index.php?/$1 [L]
</IfModule>

<IfModule !mod_rewrite.c>
    # If we don't have mod_rewrite installed, all 404's
    # can be sent to index.php, and everything works as normal.
    # Submitted by: ElliotHaughin

    ErrorDocument 404 /index.php
</IfModule>

I have my site under http://localhost/foldername/ and that URL works, but it comes up with 404 errors when I try to access http://localhost/foldername/home/
Quote:The requested URL /index.php was not found on this server.

I checked my Apache logs and it looks like it's not reading the folder name when trying to access the index.php.

Quote:[Tue Sep 14 16:08:16 2010] [error] [client 127.0.0.1] script '/var/www/index.php' not found or unable to stat, referer: http://localhost/foldername/
[Tue Sep 14 16:08:24 2010] [error] [client 127.0.0.1] script '/var/www/index.php' not found or unable to stat, referer: http://localhost/foldername/
[Tue Sep 14 16:09:53 2010] [error] [client 127.0.0.1] script '/var/www/index.php' not found or unable to stat, referer: http://localhost/foldername/

(It should be requesting /var/www/foldername/index.php instead).

The URI works when I go to http://localhost/foldername/index.php/home/

My configuration file is set up properly (as far as I can tell). I've tried changing URI protocol to all the other options and now help...

Code:
/*
|--------------------------------------------------------------------------
| Base Site URL
|--------------------------------------------------------------------------
|
| URL to your CodeIgniter root. Typically this will be your base URL,
| WITH a trailing slash:
|
|    http://example.com/
|
*/
$config['base_url'] = 'http://localhost.com/foldername/';

|--------------------------------------------------------------------------
| Index File
|--------------------------------------------------------------------------
|
| Typically this will be your index.php file, unless you've renamed it to
| something else. If you are using mod_rewrite to remove the page set this
| variable so that it is blank.
|
*/
$config['index_page'] = "";

/*
|--------------------------------------------------------------------------
| URI PROTOCOL
|--------------------------------------------------------------------------
|
| This item determines which server global should be used to retrieve the
| URI string.  The default setting of "AUTO" works for most servers.
| If your links do not seem to work, try one of the other delicious flavors:
|
| 'AUTO'            Default - auto detects
| 'PATH_INFO'        Uses the PATH_INFO
| 'QUERY_STRING'    Uses the QUERY_STRING
| 'REQUEST_URI'        Uses the REQUEST_URI
| 'ORIG_PATH_INFO'    Uses the ORIG_PATH_INFO
|
*/
$config['uri_protocol']    = "AUTO";

I assume everything will work out when I move the content to http://example.com/ (or any domain, including localhost with the content in root), but in the mean time, for development, how can I run CI within a folder?


Problems routing index.php when running CI within a folder - El Forum - 09-14-2010

[eluser]Greg Aker[/eluser]
The answer lies in your URL rewrite:

Code:
RewriteRule ^(.*)$ /index.php?/$1 [L]

/index.php vs: /yourfoldername/index.php Wink

-greg


Problems routing index.php when running CI within a folder - El Forum - 09-14-2010

[eluser]brettalton[/eluser]
[quote author="Greg Aker" date="1284515064"]The answer lies in your URL rewrite:

Code:
RewriteRule ^(.*)$ /index.php?/$1 [L]

/index.php vs: /yourfoldername/index.php Wink

-greg[/quote]

That's what I thought, but I was looking for something a little more automated. Thanks nonetheless.