CodeIgniter redirect loop in subfolder on server - codeigniter

I'm stuck with redirect loop when I deploy the files from localhost to my server.
Firefox has detected that the server is redirecting the request for this address in a way that will never complete.
The site is multilingual and I'm using .htaccess file to remove the index.php from the uri. I'm trying to deploy the site to a subfolder in my domain (i.e http://www.mydomain.com/subfolder) and ideally I want the urls like this (http://www.mydomain.com/subfolder/en/welcome)
My .htaccess file:
RewriteEngine on
RewriteCond $1 !^(index\.php|images|robots\.txt)
RewriteRule ^(.*)$ index.php/$1 [L]
I have also tried:
RewriteEngine on
RewriteBase /subfolder/
RewriteCond $1 !^(index\.php|images|robots\.txt)
RewriteRule ^(.*)$ index.php/$1 [L]
My config.php:
$config['base_url'] = 'http://www.mydomain.com/subfolder/';
$config['index_page'] = '';
$config['uri_protocol'] = 'AUTO';
My routes.php:
$route['default_controller'] = "home";
$route['404_override'] = '';
$route['^../products/(:num)'] = "products/products_list/index/$1";
$route['^../products'] = "products/products_list/index";
$route['^../products/detail/(:num)'] = "products/product/index/$1";
$route['^../(.+)$'] = "$2";
And finally MY_Config class for i18n:
class MY_Config extends CI_Config {
function site_url($uri = '')
{
if (is_array($uri))
{
$uri = implode('/', $uri);
}
if (function_exists('get_instance'))
{
$CI =& get_instance();
$uri = $CI->lang->localized($uri);
}
return parent::site_url($uri);
}
}
This setup works fine in my local environment, I access via http://local.subfolder.com, I set a virtual host to do this, but this setup doesn't work when I deploy to the server in a subfolder.
I would be really glad if someone can point where the problem is. Sorry for the long post, but wanted to give as much as information.
Thanks in advance

I'd try removing the trailing slash from RewriteBase
RewriteBase /subfolder
And also modifying your RewriteCond
RewriteEngine On
RewriteBase /subfolder
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php?/$1 [L]
I've noticed that using the ? before /$1 seems to work sometimes in CI too.
Very useful doc:
http://codeigniter.com/wiki/mod_rewrite/

if u want to use the htaccess for a particular folder., u just put your htaccess with in that folder. for ex.,
if ur using five virtual hosting like v1,v2,v3,v4,v5. And if u want to use your htaccess in v3, just put that file within that folder.

Related

laravel intervention image source not readable on deployment

Image class intervention not readable!
can anyone help me that why image not readable error show on deployment when i upload new photos to laravel project,
which is totally fine in development environment but in production has this error
enter image description here
AND this my intervention code in controller
if($request->hasFile('file')){
$nameWithExtension = $request->file('file')->getClientOriginalName();
$extension = $request->file('file')->getClientOriginalExtension();
$fileName = pathinfo($nameWithExtension, PATHINFO_FILENAME);
$newFileName = $fileName.'_'.time().'.'.$extension;
$upperExt = strtoupper($extension);
if($upperExt == 'JPEG' OR $upperExt == 'PNG' OR $upperExt == 'JPG' OR $upperExt == 'GIF'){
$request->file('file')->storeAs('public/doctor/',$newFileName);
$request->file('file')->storeAs('public/doctor_small/',$newFileName);
$request->file('file')->storeAs('public/doctor_small2/',$newFileName);
//Resize image here
$thumbnailpath = public_path('storage/doctor_small/'.$newFileName);
$img = Image::make($thumbnailpath)->resize(520, 668, function($constraint) {
$constraint->aspectRatio();
});
$img->save($thumbnailpath);
$thumbnailpath2 = public_path('storage/doctor_small2/'.$newFileName);
$img2 = Image::make($thumbnailpath2)->resize(100, 100)->save($thumbnailpath2);
}
}
Whenever I see this type of question, everyone answers that you should store it in the public folder of the project. says use this storage: link but it is not always like this, you should bear in mind that if you upload the folder in two different projects one public_html and another in a folder called for example my project things will be stored in the folder my project and laravel will search for them in public_html where they don't exist, a solution would be to put the whole project in public html by changing the .httacces this way
<IfModule mod_rewrite.c>
<IfModule mod_negotiation.c>
Options -MultiViews -Indexes
</IfModule>
RewriteEngine On
# Handle Authorization Header
RewriteCond %{HTTP:Authorization} .
RewriteRule .* - [E=HTTP_AUTHORIZATION:%{HTTP:Authorization}]
# Redirect Trailing Slashes If Not A Folder...
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_URI} (.+)/$
RewriteRule ^ %1 [L,R=301]
# Handle Front Controller...
RewriteRule ^(.*)$ public/$1 [L]
RewriteRule ^ index.php [L]
</IfModule>

URL Segment in Codeigniter

In my codeigniter project, i am working around the url parameter. Its almost working but there is some problem in the view page which is loading.
I have set all the configuration as per my knowledge. But I doubt there must be some issue in the .htaccess or routes.php file.
.htaccess file --
<IfModule mod_rewrite.c>
RewriteEngine on
RewriteBase /
RewriteCond $1 !^(index\.php|resources|robots\.txt)
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php?/$1 [L,QSA]
</IfModule>
routes.php --
$route['default_controller'] = 'home';
$route['home'] = 'home/index';
$route['faq'] = 'home/faq';
$route['privacy-policy'] = 'home/policy';
$route['doupnow-videos'] = 'home/videos';
$route['doupnow-audios'] = 'home/audios';
$route['morevideo/(:any)'] = 'home/morevideo/$1';
$route['moreaudio'] = 'home/moreaudio';
$route['404_override'] = '';
$route['translate_uri_dashes'] = FALSE;
Controller Page --
public function morevideo($cat)
{
$result['list']=$this->Home_Model->displayVideosAll($cat);
$this->load->view('header');
$this->load->view('doupnow-video-more', $result);
$this->load->view('footer');
}
Now when i navigate to "http://doupnow.com/morevideo/latest", this page getting the parameter correctly and also displaying the data based on the parameter only but the view is not getting the html and css elements like the other pages.
Kindly give me the proper direction. Thank You.
On your site, when you're linking to a script or stylesheet, you link it by doing:
/js/script.js
But you need to give the full url like this:
http://doupnow.com/js/script.js

Routes not working codeigniter

Routes not working and default controller showing error 404 when I am setting welcome as a default controller then all routes defined with the welcome controller working but my other routes and url not working.
$route['default_controller'] = "welcome";
$route['testRoute'] = 'welcome/test';
$route['testRoute/(:num)'] = 'welcome/test/$i';
All above routes are working with only welcome controller.
$route['default_controller'] = "login";
$route['loginMe'] = 'login/loginMe';
$route['logout'] = 'user/logout';
Showing error 404 for all controllers and functions.
If you put index.php after domain this will work.
http://www.example.com/index.php/login/
You should remove index.php from url by replacing in config and .htaccess
replace in config.php
$config['index_page'] = 'index.php';
by
$config['index_page'] = '';
.htaccess
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php/$0 [L]
This is what worked for me:
In config.php of config folder, use: $config['enable_query_strings'] = FALSE;
Use $config['uri_protocol'] = 'AUTO';
Use $config['index_page'] = '';
Also remember to set your base url. Mine is: $config['base_url'] = 'http://localhost/code';
Finally use the following htaccess file:
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ /code/index.php/$1 [L]
</IfModule>
NB: Remember to edit your path to index.php in the htaccess file. Hope this works for you

404 not found only index.php is working

I have finished a project and it works fine with my local server however when I put it on a live server, it gives me 404 Not Found - 404.html when I tried to access other pages. Only index.php is working the rest is not. I am using codeigniter 2.2.0. To check if there's a problem with my code I uploaded default codeigniter. I have only two pages welcome.php and one.php. Here's the live url, http://www.fhi365.com/
here is my config file.
$config['base_url'] = 'http://www.fhi365.com/';
$config['index_page'] = '';
$config['uri_protocol'] = 'AUTO';
Here is my constant
define('BASEURL', 'http://' . $_SERVER['HTTP_HOST'] . '/index.php/');
here is my route
$route['default_controller'] = "welcome";
$route['404_override'] = '';
Here is my controller
public function index()
{
$this->load->view('welcome_message');
}
public function one(){
$this->load->view('one_view');
}
I did not touch .htacces.
Can somebody help me.
Thanks.
You should trust codeigniter base_url() OR site_url() . They always return the right url.
$config['base_url'] = '';
$config['index_page'] = '';
$config['uri_protocol'] = 'AUTO';
You must pay attention to .htaccess. If is enable
if ROOT
RewriteEngine on
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php?$1 [L]
If SUBFOLDER
RewriteEngine on
RewriteBase /directory
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php?$1 [L]
This is how the problem was solved.
#Florin said to trust codeigniter.
So this is my config
$config['base_url'] = '';
$config['index_page'] = '';
$config['uri_protocol'] = 'AUTO';
#Shaiful Islam said that I need to put "?" to index.php on my constant.
This is my constants
define('BASEURL', 'http://' . $_SERVER['HTTP_HOST'] . '/index.php?/');
Wew! This works fine for me.

codeigniter 404 error at root web site

I'm trying to setup codeigniter for our website.
if I want the main page to be http://example.com
and my folder structure looks like this:
public_html\
application\
common\
system\
how do I setup codeigniter to show the page when going to http://example.com? I'm getting a 404 error when viewing it.
I edited config.php, but im not sure what to put for my base url.
my htaccess file:
RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule .* index.php/$0 [PT,L]
my routes.php
$route['default_controller'] = "HomeController";
$route['404_override'] = '';
my HomeController.php
public function index()
{
$this->load->model('HomeModel');
$this->load->view('templates/header');
$data['result'] = $this->HomeModel->function1();
$this->load->view('index', $data);
$this->load->view('templates/footer');
}
my HomeModel.php
<?php
class HomeModel extends CI_Model{
public function index()
{
}
public function function1()
{
$query = $this->db->get('work_orders');
//return $query->result();
return $query->result_array();
}
}
EDIT2:
Edit your default_controller from HomeController to homecontroller Like this:
$route['default_controller'] = "homecontroller";
and rename (if needed) your controller from HomeController.php to homecontroller.php and in your Controller itself call it Homecontroller.
Do the same for the model. call it homemodel.php (or home_model.php) in your directory and Call it Homemodel in your model itself.
Also clear your browser cache.
EDIT1:
Rename your model. I guess you called your model HomeModel.php. just call it home_model.php. this should fix your problem.
Your .htaccess file should look like:
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteCond %{REQUEST_URI} ^system.*
RewriteRule ^(.*)$ index.php?/$1 [L]
RewriteCond %{REQUEST_URI} ^LoginTut.*
RewriteRule ^(.*)$ index.php?/$1 [L]
RewriteCond $1 !^(index\.php|images|table-images|js|robots\.txt|css|captcha)
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php?$1 [L]
</IfModule>
<IfModule !mod_rewrite.c>
ErrorDocument 404 index.php
</IfModule>
This is just copied from my server and it works great.
After then, change your default_controller to:
$route['default_controller'] = "the default controller";
and if public_html is a folder you created your index page should be:
$config['index_page'] = "public_html/";
otherwise leave it blank. (if it's your server's httpdocs)
should work :)
At your router.php in config folder there is an line
$route['default_controller'] = "your controller name";
add your controller that you want to display defaultly
You can make base_url empty:
$config['base_url'] = '';
Try this working .htaccess conf:
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php/$1 [L]
</IfModule>
IF nothing helps then hosting doesn't support mod_rewrite apache module

Resources