Upload Codeigniter project to Cpanel Subdomain - codeigniter

I really-really need your help. I've done too many hours researching this problem but I can't find ideas in resolving this problem.
I have an existing website mywebsite.com and I have a system which is made with codeigniter.
Now I badly want to upload my system to cpanel so that it is now part of my website mywebsite.com as a sub-domain it would look like mydomain.mywebsite.com.
this is my config.php base url
$config['base_url'] = 'http://mydomain.mywebsite.com/';
and my index
$config['index_page'] = '';
my default route in routes.php is
$route['default_controller'] = 'users';
my my users controller (application/controller/users.php) is
<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
class Users extends CI_Controller {
function __construct() {
parent::__construct();
$this->load->model('user','',TRUE);
$this->load->helper('url');
$this->load->library('form_validation');
//enabling CORS
header('Access-Control-Allow-Origin: *');
header("Access-Control-Allow-Headers: X-API-KEY, Origin, X-Requested-With, Content-Type, Accept, Access-Control-Request-Method");
header("Access-Control-Allow-Methods: GET, POST, OPTIONS, PUT, DELETE");
$method = $_SERVER['REQUEST_METHOD'];
if($method == "OPTIONS") {
die();
}
}
function index() {
$this->load->view('login');
}
?>
my .htaccess file is
RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule .* index.php/$0 [PT,L]
But when I tried to access it, it says
404 Page Not Found
The page you requested was not found.
I tried to use the browser console to see for errors but no error appearing.
I tried to look for logs in the cpanel server still.
All the files are uploaded at CPANEL including the .htaccess (whole codeigniter system/projec)
Is my base url correct? since it is part of subdomain.
And please suggest an applicable .htaccess for me.
I tried all the post in stackoverflow but none of them matches mine.
ANy idea will be greatly appreciated

Try to empty the value of $config['base_url']. Codeigniter is smart enough to know your installation path. I dont know much of .htaccess, but this is what i always use:
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php/$1 [L]
</IfModule>
Hope this will help.

I have the same problem as you. You can try to change the permission of the subdomain folder to 755. You can change it by going to file manager, and then right-click at the root folder (where you put your .htaccess) and then click "Change Permission". The settings are as follows:
It works here.

Related

Laravel page not found

When I open the site with the server.php file, my index page is displayed (index.blade.php), and the link on that page to the list page (list.blade.php) opens successfully. I encountered issues with it recognising my javascript files when I access via server.php? However if I open the public folder it puts me at my index page and javascript files are recognised...
When I open the public folder, and I click the list link I get "Sorry, the page you are looking for could not be found."
web.php
Route::get('/', function () {return view('index');});
Route::get('list', 'IngredientsController#display');
IngredientsController
namespace App\Http\Controllers;
use Illuminate\Http\Request;
use App\Ingredient;
class IngredientsController extends Controller
{
/* Displays list of ingredients in db */
public function display()
{
$ingredients = Ingredient::all();
return view('list', compact('ingredients'));
}
}
ingredient.php
namespace App;
use Illuminate\Database\Eloquent\Model;
class Ingredient extends Model
{
}
link on index page to list page: List url
htaccess
<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...
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^ index.php [L]
</IfModule>
Laravel doesn’t use the root for including the files. So yes your IDEA see your files includes correctly but laravel it doesn’t.
See this post answer:
https://stackoverflow.com/a/28915577/5334073
Laravel uses the public folder as the ‘root’ folder. That’s just how Laravel works. To call that root you should use the URL::assets function as explain the the answer from the post I gave you.
Above RewriteEngine On I put Options +FollowSymLinks and above RewriteRule ^ index.php [L] I added RewriteBase /nameoflaravelproject/public/
I added these two lines of code and it works. Sorry I dont really understand this so if someone can explain to provide a better resource for other users then thats great.

Unable to route to static PHP page in CodeIgniter

I'm a newbie to CodeIgniter. In my 'views' folder, I've created 2 PHP pages - home.php and register.php. I've also created the header and footer PHP pages in a templates folder.
Here is my pages.php code which is the controller class:
<?php
class Pages extends CI_Controller
{
public function view($page)
{
if(!file_exists(APPPATH.'/views/pages/'.$page.'.php'))
{
show_404();
}
$data['title'] = ucfirst($page);
$this->load->view('templates/header', $data);
$this->load->view('pages/'.$page, $data);
$this->load->view('templates/footer', $data);
}
}
and here is my routes.php code:
$route['register'] = "pages/view/register";
$route['default_controller'] = 'pages/view/home';
I have not yet written anything into the .htaccess file.
My project home directory is 'ED'
I am able to navigate to the home page with this URL: http://localhost/ED
However I'm unable to navigate to the registration page with these URLs:
localhost/ED/register
or
localhost/ED/register.php
Please help as to how can I achieve this.
You have to have the index.php by default because according to CodeIgniter URLs
By default, the index.php file will be included in your URLs:
example.com/index.php/news/article/my_article
So if you want to remove the index.php, you can follow this simple step:
You can easily remove this file by using a .htaccess file with some
simple rules. Here is an example of such a file, using the "negative"
method in which everything is redirected except the specified items:
RewriteEngine on
RewriteCond $1 !^(index\.php|images|robots\.txt)
RewriteRule ^(.*)$ /index.php/$1 [L]
In the above example, any HTTP
request other than those for index.php, images, and robots.txt is
treated as a request for your index.php file.
Just put your .htaccess file(with the mod rewrite) in you main appplication folder and voila it's done.
What I did with my .htaccess was this one:
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /name_of_your_codeigniter_folder/
#Removes access to the system folder by users.
#Additionally this will allow you to create a System.php controller,
#previously this would not have been possible.
#'system' can be replaced if you have renamed your system folder.
RewriteCond %{REQUEST_URI} ^system.*
RewriteRule ^(.*)$ /index.php?/$1 [L]
#When your application folder isn't in the system folder
#This snippet prevents user access to the application folder
#Submitted by: Fabdrol
#Rename 'application' to your applications folder name.
RewriteCond %{REQUEST_URI} ^application.*
RewriteRule ^(.*)$ /index.php?/$1 [L]
#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>
<IfModule !mod_rewrite.c>
# If we don't have mod_rewrite installed, all 404's
# can be sent to index.php, and everything works as normal.
# Submitted by: ElliotHaughin
ErrorDocument 404 /index.php
</IfModule>

Flashdata not working on Chrome when hosted on server but working locally

I am using flashdata to store my search query so I can retrieve it when users navigate to the next page.
This is how I store the flashdata
$this->session->set_flashdata('searchQuery', $queryStr);
This is how I retrieve the flashdata.
$queryStr = $this->session->flashdata('searchQuery');
Flashdata is working fine locally but when I host it on my server, it does not work on Chrome(Windows) and Chrome(Android) but works on IE(Windows). Also it works perfectly fine on Chrome(iOS). I've also did a test case and it only works on IE(Windows) and Chrome(iOS). Anyone know what's wrong?
class Flashdata extends MY_Controller {
function __construct()
{
parent::__construct();
$this->load->library('session');
}
function index()
{
if ($var = $this->session->flashdata('test'))
{
echo "Found data: $var";
}
else
{
$this->session->set_flashdata('test', 'flash data test');
echo "Set data";
}
}
}
Here is my .htaccess file
# Options
Options -Multiviews
Options +FollowSymLinks
#Enable mod rewrite
RewriteEngine On
#the location of the root of your site
#if writing for subdirectories, you would enter /subdirectory
RewriteBase /
#Removes access to CodeIgniter system folder by users.
#Additionally this will allow you to create a System.php controller,
#previously this would not have been possible.
#'system' can be replaced if you have renamed your system folder.
RewriteCond %{REQUEST_URI} ^system.*
RewriteRule ^(.*)$ /index.php?/$1 [L]
#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
#This last condition enables access to the images and css
#folders, and the robots.txt file
RewriteCond $1 !^(index\.php|images|robots\.txt|css)
RewriteRule ^(.*)$ index.php?/$1 [L]
The problem is most likely caused by the last RewriteCond in your .htaccess
#This last condition enables access to the images and css
#folders, and the robots.txt file
RewriteCond $1 !^(index\.php|images|robots\.txt|css)
The above is used to list requests that shouldn't be routed to your applications index.php.
What is likely occurring is that your site includes a request for an icon/css/image/etc that you don't want routed to your application. As this request is passing through your application it is intercepting your flashdata (which is only available for the next request), which means it is becomes unavailable to your actual request for the page.
An example of this is often a favicon.ico, although there are other cases. I think Chrome will request a favicon even if one isn't specified in the <head>.
You could solve this by adding the favicon.ico to your list of excluded requests:
RewriteCond $1 !^(favicon\.ico|index\.php|images|robots\.txt|css)
It's possible that this is not caused by a favicon.ico, but another request for something completely different. The best way to get to the bottom of this is to log all your requests to a file and check what is happening at that point in the code.

How to use redirect helper in codeigniter

I'm trying to redirect after the login.
After login it has to call the home controller's method.
For example if the url is test.com, I have two controllers: logincontroller and home. So the first url is:
test.com/logincontroller/login
After that, i want to redirect to
test.com/home/getfirstpage
So I used redirect function like this
redirect("/home/loadfirstpage", 'refresh');
But the problem is that the url get screwed up.
After redirect function it goes to this url:
test.com/logincontroller/test.com/home/getfirstpage
I want to fix to
test.com/home/getfirstpage.
How can i do this?
Edit: I'm assuming this is cuz of the .htaccess to delete index.php
This is my .htaccess
RewriteEngine on
RewriteCond $1 !^(index\.php|images|robots\.txt)
RewriteRule ^(.*)$ /index.php/$1 [L]
Check your config file and set the $config[base_url] correctly.
Load:
$this->load->helper('uri');
Then in controller:
redirect('controller/method', 'refresh');
The problem comes from the forward slash you put in the redirect
redirect("/home/loadfirstpage", 'refresh'); instead do this redirect("home/loadfirstpage", 'refresh');
Try this:
redirect("home/loadfirstpage", 'refresh');
And set your .htaccess file to:
RewriteEngine on
RewriteCond $1 !^(index\.php|images|robots\.txt)
RewriteRule ^(.*)$ index.php/$1 [L]
And make sure that you have set $config['index_page'] in config.php:
$config['index_page'] = '';

Codeigniter in localhost WAMP Windows

I try to use Codeigniter in localhost with WAMP.
Problem is, that I can open just basic function in basic controller, and when I tried to use root like site/controller/function, its do not work. Result is that it put me back to wamp start page, or text that page not found.
Mostly I found solutions about makingthe .htaccess file, and many variations what to put in it.
To uncomment rewrtie mod in wamp .conf file. And in my web page to leave index_page empty.
But It do not work for me.
My controller:
class Home extends CI_Controller {
function index() {
$this->load->view('index');
}
function slide() {
$this->load->view('slider');
}
}
And my web page is in: www/mysite/....
Try this .htaccess
RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond $1 !^(index\.php|indexcp\.php?|resources|robots\.txt)
RewriteRule ^([A-Za-z0-9_/.-]+)$ index.php?$1
RewriteRule ^(CSI) index.php?/CSI
AddType text/x-component .htc
EDIT
Add the above code here
Don't change any thing in CI system..
Once check this repo

Resources