CodeIgniter Forums

Full Version: URLs don't work when application is in web root
You're currently viewing a stripped down version of our content. View the full version with proper formatting.

El Forum

[eluser]Unknown[/eluser]
I'm rewriting this to clarify:

I'm confused about how, if the application folder is not in the usual location inside the base_url folder, the techniques described in the documentation for navigation are supposed to work. Or at least, they aren't working for me. I put my app and system above the web root and redirected to them, because the installation instructions say:
Quote:For the best security, both the system and any application folders should be placed above web root so that they are not directly accessible via a browser.
… and, while I'm at it, the User Guide says this can be done at http://ellislab.com/codeigniter/user-gui..._apps.html:
Quote:If you would like to rename your application folder you may do so as long as you open your main index.php file and set its name using the $application_folder variable
It is possible to move your application folder to a different location on your server than your system folder. To do so open your main index.php and set a full server path in the $application_folder variable.
$application_folder = "/Path/to/your/application";
So that is what I did: I set my system and application folders above the web root, and made my system and application variables
Code:
$application_folder = ‘/wamp/codeigniter/application’;
$system_path = ‘/wamp/codeigniter/system’;
And the first page works just fine. But standard navigation (as described in the tutorial) does not: I get Not Found. The URLs are all still looking for files relative to the base_url. I followed the tutorial, creating a home page and appending '/index.php/view/pages' to my URL and – 404. I then altered the controller code from this:
Code:
if ( ! file_exists('application/views/pages/'.$page.'.php')) {
to this
Code:
if ( ! file_exists(APPPATH.'/views/pages/'.$page.'.php'))

And the navigation DID work. I don't see this anywhere in the documentation however, which makes me think this isn't the right way to go about it.
For that matter, how would a simple href URL work? Any tip or advice much appreciated.

El Forum

[eluser]Aken[/eluser]
Your modification is correct - the tutorial assumes you're using CodeIgniter as it comes out of the package, and not modifying paths or folder names.

You can also check if your index.php specifies the VIEWPATH constant (I don't remember what version it was added in - might only be in the dev 3.0 version). If it has that, you can use that constant instead to make things even more simple.

El Forum

[eluser]Unknown[/eluser]
Thanks Aken for confirming about the tutorial and that I'm at least on the right track with the modification. I don't see the VIEWPATH, so it must be in the unreleased build. One more question: how can I adapt navigation such as the below if the application isn't in the site's directory:
Code:
<a href="pages/view">Go to a page</a>
Using the class/method/id/ style of uri here fails because the index page doesn't find the 'pages' controller. Is this where I need to add cases to my routes.php file?

El Forum

[eluser]Aken[/eluser]
Not 100% sure I'm understanding your question exactly, but you'd use routes to direct a non-existant URL to a valid class/method/id URI. You can also use the URL helper functions site_url() or anchor() to generate URLs that include index.php automatically. Which is good for if you remove index.php via .htaccess in the future.