Codeigniter routes are not show anything - php

I'm dealing with a codeigniter app that I haven't developed and is not working , if I request the main url the main controller is not called(and every route I've tried gets an 404 error), the browser shows the directory listed.
Another project on the same server with codeigniter without any changes works correctly,
Anyone know what could be the problem??

Make sure you have added the project folder in the base_url like below
$config['base_url'] = 'http://'.$_SERVER['SERVER_NAME'].'/project_folder/';
$config['index_page'] = '';
and, update your .htaccess file with this code
Options +FollowSymLinks
Options -Indexes
DirectoryIndex index.php
RewriteEngine on
RewriteCond $1 !^(index\.php|images|robots\.txt)
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php/$1 [L,QSA]

Related

URL-rewriting Codeigniter htaccess

Since I changed a website to another server, I have a problem that I can't access the website on domain.com/codeigniter/ . My default controller is info/
It worked with http://www.domain.com/codeigniter/info/ and http://www.domain.com/codeigniter/info/model/
$route['default_controller'] = "info/";
$route['404_override'] = '';
$route['info/(:any)'] = "info/view/$1";
.htaccess
RewriteEngine on
RewriteCond $1 !^(index\.php|images|robots\.txt)
RewriteRule ^(.*)$ /index.php/$1 [L]
But on the new server it doesn't work. The problem is that it always ends in http://www.domain.com/index.php and not the index.php of the directory of the codeigniter installation..
What could be the problem?
there are a few things that make CodeIgniter work in secondary folder: first of all, you must change $config['base_url'] = http://www.domain.com/codeigniter/'; in application/config/config.php.
Then, of course, change .htacces file to this:
<IfModule mod_rewrite.c>
Options +FollowSymlinks
RewriteEngine On
# block hidden directories
RewriteRule "(^|/)\." - [F]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ ./index.php/$1 [L,QSA]
</IfModule>
Php mod_rewrite module is needed.
After changing the .htacces and leaving the 'base_url' empty (http://www.domain.com/codeigniter/ doesn't work).
I have the following problems:
http://www.domain.com/codeigniter/ --> ERROR 404 from CI
http://www.domain.com/codeigniter/info/ --> No input file specified
http://www.domain.com/codeigniter/index.php/info/ --> OK
EDIT: Problem solved.. I forgot a ? after the index.php in the .htaccess & I changed the default controller in routes.php to info/view/home/
It was a combination of multiple things... It is strange that it worked on the old hosting. It was obviously wrong..

Unable to open a controller(PHP web page) in 000webhost.com. "error404.000webhost.com/"

I have just uploaded all file of my test website to 000webhost.com domain.
My site is farazphptest.comxa.com
I was working on Codeigniter before uploading the site. All of my controllers are working fine on my localhost, but after uploading the site on server when i try to access a controller say farazphptest.comxa.com/welcome where "Welcome" is my webpage/controller, it does not work and opens "error404.000webhost.com/?" All of my controller including "welcome" are working fine on localhost, but after uploading website on domain only the home page loads perfectly.
This is the 1st time i have put a site on web, do tell me if i am missing out some tricks. I have just simply copied my file on web as stated. Thanks
Here is my .htaccess file used in both for localhost and on server.
<IfModule mod_rewrite.c>
RewriteEngine on
RewriteBase /faraztest
RewriteCond $1 !^(index\.php|public|\.txt)
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php?$1
</IfModule>
<IfModule !mod_rewrite.c>
ErrorDocument 404 /faraztest/index.php
</IfModule>
An alternative solution is to create sub-domain on 000webhost.com with project name , and call the project from sub domain url Directly, it will be like this :
From Cpanel got to Subdomains
Create new subdomain with project folder name. ex : test.farazphptest.comxa.com
Overwrite the created subdomain folder with your project folder. ex : test
Edit your .htaccess in your main uploaded project folder to be like this :
RewriteEngine on
RewriteBase /
RewriteCond $1 !^(index\.php|public|\.txt)
RewriteRule ^(.*)$ index.php/$1 [L]
now you can call your project directly from the new subdomain url.
ex : http://test.farazphptest.comxa.com
Following solved my problem
My .htccess file is
# index file can be index.php, home.php, default.php etc.
DirectoryIndex index.php
# Rewrite engine
RewriteEngine On
# condition with escaping special chars
RewriteCond $1 !^(index\.php|robots\.txt|favicon\.ico)
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ ./index.php/$1 [L,QSA]
and it worked like charm!

Removing index.php from url works on localhost and doesn't work online

I work on PHP project using codeigniter, I remove the index.php from URL locally, here is my .htaccess
RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule .* index.php/$1 [PT,L]
When I upload the project online routes don't work at all, and I need to set index.php with plain url instead of the route!
for example instead of writing index I have to write
index.php/product_management_controller/index
If I write index it doesn't work even if I update the route to include index.php !! That means the routes are also not working!
my current route is
$route['index'] = "product_management_controller/index";
And here's a few things I've set in my config.php file:
$config['base_url'] = '';
$config['index_page'] = '';
$config['uri_protocol'] = 'REQUEST_URI';
What is the solution!!
It works properly locally!!
Your server that your hosting on will need to allow .htaccess files, in your Apache config you will need to add:
AllowOverride All
to your Apache config. Then restart the Apache server.
You could also try
Options +FollowSymLinks -MultiViews
RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule .* index.php/$1 [PT,L]
There is an documentation for removing index.php from url on codeigniter
https://ellislab.com/codeigniter/user-guide/general/urls.html
By the way you are on godaddy shared server as per the comments and you don't have access to apache config file, but the good news is you don't need to worry rewrite mode is on for you by default. :)

codeigniter index.php file mod rewrite

Hi i am new to codeigniter and using this as my url
http://localhost/codeigniter/index.php/site
and have included following htaccess file
RewriteEngine On
RewriteBase/codeigniter
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php/$1 [PT,L]
after including this htaccess filr to codeigniter folder the web page stops working on both
http://localhost/codeigniter/index.php/site
and
http://localhost/codeigniter
basically i need
http://localhost/codeigniter
to work
please help
Thanks
You are missing a whitespace between your RewriteBase and the base URI:
RewriteBase /codeigniter
This is probably why things has stopped working (a server error status 500, which you could find in your error log).
Use this one,
RewriteEngine on
RewriteCond $1 !^(index\.php|images|robots\.txt)
RewriteRule ^(.*)$ /index.php/$1 [L]
For more details Click Here.
In order to have your codeigniter site default to the site controller you need to update config/routes.php to set the site controller as the default route.
For the rewrite issue see #Repox's answer.

CI not working locally

Instead of working live on my site I've decided to try and work locally and install new version later on my live site.
So I'm working with Codeigniter and have the following struture.
/htdocs/kow(site)/kowmanager(cms)
When I load https:localhost/kow it loads the correct controller however for some reason its not reconizing that kowmanager is a sub directory of kow with its own application folder and it should be loading the default controller that is set in its routes file. When I load https://localhost.com/kow/kowmanager it loads a page that says index of /kow/kowmanager and then a link to the parent directory. Which isn't anything CI related.
Inside the kow directory this is my .htaccess file. Is this the problem?
RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php?/$1 [L]
RewriteEngine On
RewriteBase /kowmanager
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php?/$1 [L]
I'm using xxamp.
You need an index.php-page for each application as stated by the manual.
So I think you should copy your index.php to indexManager.php and in it change the application folder.
$application_folder = "kowmanager";
About the rewrite I am not sure but I think it is in line with:
RewriteEngine On
RewriteBase /kowmanager
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ indexManager.php?/$1 [L]
RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php?/$1 [L]
are you using a .htaccess to remove index.php from urls ?
is /htdocs/kow the base directory of your project where CI is installed ?
you need to put kowmanagers in the controllers directory, and specify which controller to call, I'm not sure CI supports calling default controllers from directories unless you specify it in the routes.php config file.
Anyway, please give further information if you want a precise answer.
What is in kowmanager and why do you have two rewrites? If your directory structure is how I assume it is, you might get away with just removing the second kowmanager directive from your .htaccess file.
Which folder is codeigniter in? All you want to do is rewrite the url to remove index.php, but unless you're mapping the url to codeigniter's index.php, it will never be able to load controllers.
Apache has a lot of info on url rewrite. Its a lot of reading and the behavior is always pretty finicky, but maybe it will help you:
Otherwise, more info will help us help you. P.S. I'd also tag this with apache, as that is where the problem is, and you're more likely to get people who know a lot about apache to view your question.

Categories