CodeIgniter Forums
system and application folders above the web root - Printable Version

+- CodeIgniter Forums (https://forum.codeigniter.com)
+-- Forum: Using CodeIgniter (https://forum.codeigniter.com/forumdisplay.php?fid=5)
+--- Forum: Installation & Setup (https://forum.codeigniter.com/forumdisplay.php?fid=9)
+--- Thread: system and application folders above the web root (/showthread.php?tid=61309)



system and application folders above the web root - tj_gumis - 04-07-2015

Hi

To make a long story short. My folders structure is as follows :
Quote:project
application
system
public
index.php
My .htaccess :
Code:
RewriteEngine On
RewriteCond %{THE_REQUEST} /public/([^\s?]*) [NC]
RewriteRule ^ %1 [L,NE,R=302]
RewriteRule ^((?!public/).*)$ public/$1 [L,NC]
but locally, after url taped :
Quote:localhost/project
routers method _set_request() receives as argument an array :
Quote:segments ( [0] => project )
and makes directly "project" controller's name.

What am I missing ? Is it a configuration issue or something else ?

Thx in advance for any response.


RE: system and application folders above the web root - tj_gumis - 04-08-2015

Finally within _parse_request_uri() of CI_URI class, I modified :
PHP Code:
if (isset($_SERVER['SCRIPT_NAME'][0]))
{
    if (
strpos($uri$_SERVER['SCRIPT_NAME']) === 0)
    {
        
$uri = (string) substr($uristrlen($_SERVER['SCRIPT_NAME']));
    }
    elseif (
strpos($uridirname($_SERVER['SCRIPT_NAME'])) === 0)
    {
        
$uri = (string) substr($uristrlen(dirname($_SERVER['SCRIPT_NAME'])));
    }

into:
PHP Code:
$script_name = (string) str_replace($this->config->item('public_folder_name'), ''$_SERVER['SCRIPT_NAME']);
       
if (isset(
$_SERVER['SCRIPT_NAME'][0]))
{
    if (
strpos($uri$script_name) === 0)
    {
        
$uri = (string) substr($uristrlen($script_name));                
    }
    elseif (
strpos($uridirname($script_name)) === 0)
    {
        
$uri = (string) substr($uristrlen(dirname($script_name)));  
    }

and it works even with hmvc installed.


RE: system and application folders above the web root - CompuTronix - 05-08-2015

Anyone with significant CI experience have a better solution than the one presented above? I'm asking because I am having the exact same problem as OP, and I've looked all over the Internet for a solution to no avail.

I've tried many different combinations and configurations of .htaccess, Apache vhosts, and mod_rewrite, but nothing works. CI keeps thinking that the subdirectory that my code resides in is part of the default controller name.

I'd like to not have to modify CI core files in order to get this to work, but I will if I struggle with this for too much longer.

Thanks all


RE: system and application folders above the web root - CroNiX - 05-10-2015

You don't have to modify core classes, and really shouldn't. You extend them and can override methods or add new ones.
http://www.codeigniter.com/user_guide/general/core_classes.html#extending-core-class


RE: system and application folders above the web root - kilishan - 05-10-2015

Try adding a RewriteBase /project to your htaccess file.


RE: system and application folders above the web root - pdthinh - 05-11-2015

I create my app as below:

1. Folder structure:
-----------------------------

Code:
application
system
public
 + index.php
 + .htaccess
 + (other resources)
(other files)


All the files in the public folder are available to all users through http.
Note: the index.php was moved to public folder.

2. Modify the index.php:
-----------------------------

PHP Code:
$system_path '../system';
$application_folder '../application'


3. Content of .htaccess:
-----------------------------

Code:
Options +FollowSymLinks
RewriteEngine On

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


And that works for me.