how to set up second codeigniter app in subdomain - codeigniter

I have a web app frontend and backend, the frontend was made in codeigniter framework, the backend was also made in another codeigniter framework.
frontend : flum.com
backend : subdomain.flum.com
the frontend works fine, but i'm having a hard time on the backend, it always shows error 404.
in my shared hosting file manager,
frontend - codeigniter app 1
/root/username/application
/root/username/system
/root/username/public_html/index.php
/root/username/public_html/public/(css, js, images folders)
backend - codeigniter app 2
/root/username/subdomain_application
/root/username/subdomain_system
/root/username/public_html/subdomain/index.php
/root/username/public_html/subdomain/public/(css, js, images folders)
both have the same database settings
application/config/database.php
$db['default'] = array(
'dsn' => '',
'hostname' => 'localhost',
'username' => 'user',
'password' => 'pass',
'database' => 'mydatabase',
'dbdriver' => 'mysqli',...
);
frontend application/config/config.php
$config['base_url'] = 'http://flum.com';
$config['index_page'] = '';
-I edited the index.php on main ci app
$system_path = '/root/username/application';
$application_folder = '/root/username/system';
backend application/config/config.php
$config['base_url'] = 'http://subdomain.flum.com';
$config['index_page'] = '';
-I edited the index.php on main ci app
$system_path = '/root/username/subdomain_application';
$application_folder = '/root/username/subdomain_system';
both have the same .htaccess:
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php/$1 [L]
i expected the backend will be working fine with my frontend app given that backend is in a complete separated codeigniter app.

Here is another file structure you can try. Hopefully, it will give better results.
/root/username/front/application/
/root/username/front/public_html/index.php
/root/username/front/public_html/.htaccess
/root/username/front/public_html/assets/(css, js, images folders)
/root/username/back/application/
/root/username/back/public_html/index.php
/root/username/back/public_html/.htaccess
/root/username/back/public_html/assets/(css, js, images folders)
Both front and back can use the same system directory
/root/username/system/
Both front and back need their own index.php. The system path is the same in each.
/front/public_html/index.php
$system_path = '/root/username/system';
$application_folder = '/root/username/front/application';
/back/public_html/index.php
$system_path = '/root/username/system';
$application_folder = '/root/username/back/application';
A .htaccess is needed in both 'public_html' directories, but they are identical to the one you show in the question.
The $config['base_url'] values you used will be fine in the appropriate config.php files.
Because you use .htaccess I assume you're using Apache. The blocks in the Apache site conf files for both front and back will need the DocumentRoot values set to the appropriate public_html directory path.
Database config shown in the question should work for both front and back.
The CodeIgniter documentation has yet another suggestion for Running Multiple Applications that is similar to the structure I show. It uses two index.php files, but at least one of them must have a different name. In your case, perhaps the front uses index.php and the back uses backend.php
To browse to a backend controller named "admin" the URL would be https://subdomain.flum.com/backend.php/admin
It would require a more complex .htaccess to remove index.php or backend.php from the URL. To be honest, I'm not sure what that looks like and is the reason for the file structure presented.

Related

.htaccess redirects in Laravel and on Forge

When migrating an old project to a new, Laravel based project, we would need to redirect (301 Header) old routes to new routes, e.g.
/index.php?page=shop ==> /shop
/index.php?category=abc&product_id=123 ==> /abc/item-123
For this, we've prepared a proper .htaccess file that works perfectly on the old project. However when we deploy the new project and change the domain DNS, the htaccess also needs to be in the new folder.
In Laravel, we do have /public/.htaccess, however, adding our .htaccess pieces won't work together with Laravel Forge. It is a simple .htaccess file that looks like:
<IfModule mod_rewrite.c>
# Enable Rewrite Engine
RewriteEngine On
RewriteBase /
# index.php?page=user&sub_page=settings
RewriteCond %{QUERY_STRING} ^page=user&sub_page=settings$
RewriteRule ^index\.php$ /users/notifications/permissions/edit [R=301,NC,L,QSD]
(... and so on)
</IfModule>
So now we are wondering: how can we make it work, that it will forward old routes to the new routes in the same project based on Laravel?
Laravel Forge uses an nginx.conf file (which you can configure in forge) instead of the .htaccess file.
You can use the nginx reference to re-create your settings: https://nginx.org/en/docs/. You should look at the sections: location and redirect.
Hope This Helps!

CodeIgniter giving a 404 not found on public server only

Description
I have a site "searchnwork.com". It uses CodeIgniter. Every page except the home page loads fine.
If you go to searchnwork.com, it shows the CI 404 error page.
If you go to searchnwork.com/index.php/users, it shows the UserSignUpController page, which is good.
If I set the $route['404_override'] = 'UserSignUpController', I still get a 404.
Everything works fine on my local server.
Question
Why am I getting a 404 for searchnwork.com despite the override?
Why am I getting a 404 for searchnwork.com in the first place instead of my default controller?
Code
$route['users'] = "UserSignUpController"; // This loads fine.
$route['default_controller'] = "UserSignUpController"; // This gives a 404...
$route['404_override'] = 'UserSignUpController'; // This doesn't redirect...
Case sensitive file names.
On MAMP it doesn't seem to care about capitalization. When I uploaded to an actual linux server, CapitalizedFileNames started to fail, since it only searchs for lowercasefilenames. I guess you should use underscores.
Weird that it only fails for index.php.
You need to install a .htaccess on the server root
RewriteEngine on
RewriteCond $1 !^(index\.php|images|robots\.txt)
RewriteRule ^(.*)$ /index.php/$1 [L]
Also make sure your /application/config/config.php is set up properly (these can by left blank and should still work properly)
$config['base_url'] = '';
$config['index_page'] = '';

Laravel not honoring the routes.php file

I'm having a strange problem. I recently moved my Laravel site from one directory to another in my localhost (on a Mac). Nothing has been right since. I had to change my .htaccess from the standard Laravel 4 .htaccess to:
Options +FollowSymLinks
RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . index.php [L]
which is the alternative Laravel .htaccess for L4. That at least makes my public folder not be forbidden. But now Laravel just completely ignores the routes file. In fact, all routes (those in the file and those not) seem to valid and none seem to call a 404 error, even though I try to call both routes that exist and routes that don't. I even deleted everything in the routes file except the base route and nothing changed.
How is it possible that routes that don't exist can be called and I don't get the page not found error? All I get is a white screen. The same is true except for the base route. Why is it honoring only the base route (which is '')? If I change that route to one of the other controllers, it will call that controller. In short, the only route that works is ''. Why has everything changed since I moved the site?

How can I redirect image 404 error on Amazon S3 to my own server

Is it possible to redirect a 404 error on Amazon S3 server to my own server? Here's the case in my website:
A user uploaded a file, called abc.jpg. I have a set of image types, such as crop or thumb.
When someone access /img/abc.crop.jpg, the webserver check and look for the file /img/abc.crop.jpg. If they found it, webserver will throw the file.
But when the program can't found that file, this .htaccess file will route it to a program:
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php/$1 [L]
So it will go to index.php/img/abc.crop.jpg, where the "img" controller/program will look for abc.jpg and generate a file called abc.crop.jpg on the img folder. So next time another user access the abc.crop.jpg, the program doesn't need to regenerate the file anymore.
Now, when I am using the Amazon S3, I have to generate ALL the different sizes (crop, thumb, etc) one by one to avoid 404 error. The purpose of the above technique is to conserve space. I wanted the flow to be kept consistent with the current condition. Anybody have any idea on how to manipulate S3 404 error so that they'll redirect to my server? Ie. http://bucket.s3.amazonaws.com/img/abc.crop.jpg redirect to http://mysite.com/img/abc.crop.jpg ?
This is my workaround to identifying the 404 error.
Enable S3 web service
Configure the Error Document to a file-not-found.jpg
$result = $s3->getObject(array(
'Bucket' => 'my bucket',
'Key' => 'path/to/file'
));
Use md5 or crc32 to identify if the returned object is file-not-found.jpg
Redirect to your own server
If you're using codeigniter, have a look at the reserved routes http://codeigniter.com/user_guide/general/routing.html. you can specify a specific controller for any 404 error.

jquery.ajax in codeigniter

I am having a problem in implementing jquery.ajax in codeigniter. I want to send the control to a specific function of a controller. I am setting the url in my javascript function like this
var url='<?php echo('First/index');?>';
var ajaxoptions={url:url,success:submit_ajax_response};
First is my controller and index is my function where I want to send the control. When I click on the event on which it is called the following url is formed
http://localhost/codeigniter/First/index
The URL is fine but it is generating the error of 404. I have done such kind of operations various times in zendframework but unable to accomplish this job in codeigniter. I have noticed one thing that if I add index.php in the url it works fine. By adding index.php the url becomes like
http://localhost/codeigniter/index.php/First/index
I am astonished how to remove index.php from route file. I have only two lines in route.php file
$route['default_controller'] = "First";
$route['404_override'] = '';
I have already made my controller as the default controller.
Am I doing correct? What is the problem and how to accomplish this job`
You need to check a couple of things. First, in /application/config/config.php make sure index file is set to this:
$config['index_page'] = '';
Second, make sure you have correct .htaccess. This should be at the root of your public directory (same place as your index.php):
<ifModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
Options FollowSymLinks
#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>
I notice the part that is missing form your URL is the "index.php" thing that CodeIgniter has.
Change your code to this: (You need URL helper, so load that before this):
var url="<?php echo (index_page() . 'First/index');?>";
var ajaxoptions={url:url,success:submit_ajax_response};
index_page returns your site "index" page, as specified in your config file.
In order to remove index.php from your CodeIgniter links see here.

Resources