CodeIgniter routing issues with subdirectories - codeigniter

I am working on a web app that is located in a child folder of a folder in my htdocs. Like this:
http://localhost/folder/another_folder/index.php
I can force routing to my controllers by getting:
http://localhost/folder/another_folder/index.php/controller
But I cannot get my routes to behave as expected:
$route['auth/login/(:any)/(:any)'] = 'auth/login/$1/$2';
I also tried:
$route['auth/login/(:any)/(:any)'] = 'folder/another_folder/auth/login/$1/$2';
$route['another_folder/login(:any)/(:any)'] = 'auth/login/$1/$2';
And various other permutations. In all cases I get CI 404s or standard 404s. I need a solution that is portable, so when I publish this in the test server where it'll be at on level of subdirectory, and when I publish to production where it'll be root I only need to change one (or fewer!) lines of code. Thanks for your insight!

Configuring base_url in config.php seems to be the trick for this!

Related

How to name api routing on a webhost sub folder

I have always thought the api controllers where not found by physical paths. The reason I ask is I have a website example.com I created a folder example.com/testing and uploaded my project to there. When I ran it I got errors saying that none of the apiControllers could be found. So I changed /api/apiCustomers to /testing/api/apiCustomers. It then worked, well not the actual posting of any new records. It did locate and retrieve all the records from the database though. But it doesn't seem like that is what I would actually need to do? I have a domain with WinHost and the default publish folder is example.com/myApp
AM I looking at this the wrong way?
To handle request where you do not know the root path, you can use (as in ASP.NET) the ~-character like this:
~/api/apiCustomers
~ will then be replaced by the root (i.e. /api/apiCustomers for prod and /testing/api/apiCustomers for your test environment)

How do I do a redirect/rewrite rule for S3 using s3_website?

I am migrating from a hosted site to hosting wordpress in s3. One of the things I'd like to do is have a folder at the root level into which I can put all the files. This makes it easier to delete if I need to.
The problem is that my prior has the format of blog.site.com/post.
If I put all the posts in a separate folder, the format shows up as blog.site.com/folder/post
Question: Is there a way to write a rewrite rule using s3_website to rewrite/redirect blog.site.com/folder/post to blog.site.com/post?
This is based on the sample code from s3_website:
routing_rules:
- condition:
key_prefix_equals: site/folder
redirect:
host_name: www.site.com
replace_key_prefix_with: /
http_redirect_code: 301
When I try it, I get an error. Thoughts?
Try this for key_prefix_equals
key_prefix_equals: folder/
I am not positive this is the correct solution.

Installing secure CodeIgniter with Sparks

Installing Sparks assumes that you are abiding by the default CodeIgniter installation pattern; extracting the application, system, and user guide folders, along with with a index.php and a license file into your web root.
However, many of us pull the application and system folders out of the web root for security reasons and re-route the $system_path and $application_folder variables in the main index.php file.
This separation tends to break Spark installs. In particular, the simple example-spark used in the getsparks installation instructions.
Getting an error:
An Error Was Encountered Cannot find
spark path at
sparks/example-spark/1.0.0/
I maintain the following directory structure:
CISYS
V202
V200
project1_application
project2_application
project3_application
www (public html)
project1
css
js
images
etc
project2
etc
What must I reroute to achieve both security + sparks? Open to suggestions of any sort. How do you set up your installation?
To answer my own question: The solution was in the MY_Loader.php file. By modifying the SPARKPATH variable on line 43, one can reroute the location of all sparks! Cheers!

System folder Codeigniter

I have an application running with Codeigniter, its name is SAF.
folder structure:
/SAF/index.php
/SAF/application/
/SAF/system/
Now, i'm going to develop other application that going to use at folder structure:
/BOL/index.php/
/BOL/application/
So, can I alter the $system_path variable of index.php in BOL structure to i'll use the system folder of SAF application?
$system_path = '../SAF/system';
Are there any problem in this?
It will work, but unless your BOL application explicitly depends on SAF, I recommend moving system out of both
/system/
/SAF/...
/BOL/...
This is how I used to do it and this way the content of each directory is specific only to its own application (it avoids someone messing with /SAF/system without taking into account the fact that his changes will affect BOL as well).
No, that should work perfectly.

Codeigniter App on EC2 - Helpers not loading

I recently just started to migrate over a CI application to Amazon's EC2 service. To test I set up a micro instance of ubuntu and a LAMP stack. PHP, MySQL, HTTPD are all working beautifully. The one issue i'm having now is that when I run my application I receive an error saying that my helpers won't load. The helpers in particular that aren't loading are the ones in subdirectories in the helpers directory ie: /var/www/system/application/helpers/subdirectory/foo_helper.php
The helpers are being autoloaded and in my autoload.php config file they are written like:
$autoload['helper'] = array('subdirectory/foo', 'foo2',...);
Has anyone run into this issue, or have any pointers on where I could go look in my configuration to resolve this?
Thanks for the help!
I'd try debugging the helper function of the Loader class, in particular these lines :
system/libraries/Loader.php
elseif (file_exists(APPPATH.'helpers/'.$helper.EXT))
{
include_once(APPPATH.'helpers/'.$helper.EXT);
}
This is the code that will be hit when including application helpers. Check what path CodeIgniter is trying to include. Double check that the path exists - everyone makes typos now and again ;-)
I think the issue is that when I moved from Windows to Linux I forgot to take into account that linux is case-sensitive. So now I need to go through and rename my files and folders.
But this still doesn't solve the issue where it seems like the page is being cached and I'm not able to refresh and see my changes. Is there any way to force the page to grab a fresh copy from the server on every refresh?

Resources