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]
I have some problem. In development I'm using php 7 and my website work well. But in production it using php 5.4 and I have problem in removing index.php. My website hosted in subfolder just like myhost/mywebsitefolder.
The problem is when using url function. example, when I accesing 'dashboard' page it will redirect to 'login' page and the url is like myhost/mywebsitefolder/login and it return 404 page not found. When I add index.php before login (myhost/mywebsitefolder/index.php/login) it work well but I must replace all of my url by adding index.php. Are there any solution. My .htaccess is just like this.
RewriteEngine on
RewriteBase /mywebsitefolder/
RewriteCond $1 !^(index.php|resources|gallery|json|slider|robots.txt)
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php/$1 [L,QSA]
Try with a slash before the dots, like:
DirectoryIndex index.php
<IfModule mod_rewrite.c>
RewriteEngine on
RewriteBase /mywebsitefolder
RewriteCond $1 !^(index\.php|resources|gallery|json|slider|robots\.txt)
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php/$1 [L,QSA]
</IfModule>
<IfModule !mod_rewrite.c>
ErrorDocument 404 index.php
</IfModule>
And in application/config/config.php and clear the index page config value:
// Old
$config['index_page'] = "index.php";
// New
$config['index_page'] = "";
Sometimes you need to enable it the rewrite module, run "apache2 enable module rewrite":
sudo a2enmod rewrite
You need to restart the webserver to apply the changes:
sudo service apache2 restart
Hope it works!
If no, there is others threads with the same problem,you can take a look:
- Remove index.php from codeigniter in subfolder
- Remove index.php from Codeigniter URL in subfolder with Wordpress in root
- Using htaccess to remove codeigniter index.php in a subdirectory
I have learned and make website using CodeIgniter. I want to create this system module base so I have created multiple folders and controller,views and model for each module and it's working fine. I want to remove index.php and hide query string like pass user id in URL. I have tried htaccess code which given user guide but it did not work.
Current URL :
mysite/sitename/index.php/departments/departments/delete_department/14
Require :
mysite/sitename/departments/departments
I have tried below code in htaccess but it does not work as expected, it displays page not found error.
RewriteEngine on
RewriteCond $1 !^(index\.php|images|fonts|js|css|robots\.txt)
RewriteRule ^(.*)$ /index.php/$1 [L]
My directory structure is something like that
My site
|_application
| |_ Controller
| |_Login (folder) // module folder
|_Models
| |_pages
|
|_views
|_login (folder) // module folder
1) you should have Rewrite mod on apache
2) You should change application/config/config.php
$config['index_page'] = 'index.php'; to: $config['index_page'] = '';
3) after that I see that you are having a subdirectory of sitename so you should add that on your .htaccess as your RewriteBase which will result in an .htaccess like this:
RewriteEngine On
RewriteBase /sitename/
RewriteCond $1 !^(index\.php|resources|robots\.txt)
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php/$1 [L]
If i understand your folder structure right, then your root folder is mysite and your CI application is located at mysite/sitename . if this is the case try checking out the last part of the rewrite
RewriteRule ^(.*)$ /index.php/$1 [L]
As it currently tries to load an index file that is located on your root folder (mysite) and under my understanding your index file is actually located on mysite/sitename, so you can try this:
RewriteRule ^(.*)$ /mysite/index.php/$1 [L]
Using your FTP client, create a new file named .htaccess (including the leading dot) in the same folder as your site’s main index.php file.
Then add the following code to this newly created .htaccess file:
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
# Removes index.php from ExpressionEngine URLs
RewriteCond %{THE_REQUEST} ^GET.*index\.php [NC]
RewriteCond %{REQUEST_URI} !/system/.* [NC]
RewriteRule (.*?)index\.php/*(.*) /$1$2 [R=301,NE,L]
# Directs all EE web requests through the site index file
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ /index.php/$1 [L]
</IfModule>
If your site’s system directory (/system/) has been renamed and is still accessible by URL, modify the RewriteCond line above:
RewriteCond %{REQUEST_URI} !/newdirectoryname/.* [NC]
If you are running EE from a sub-directory rather from the root of your domain (e.g. http://example.com/myeesite/ instead of http://example.com/), just remove the slash preceding index.php in the RewriteRule line above, like so:
RewriteRule ^(.*)$ index.php/$1 [L]
If you are running EE from a sub-directory and it still doesn’t work after removing the slash, you may need to specify the sub-directory in your rewrite rule. For example, if your sub-folder is named testing, change:
RewriteRule (.*?)index\.php/*(.*) /$1$2 [R=301,NE,L]
To:
RewriteRule (.*?)index\.php/*(.*) testing/$1$2 [R=301,NE,L]
And change:
RewriteRule ^(.*)$ /index.php/$1 [L]
To:
RewriteRule ^(.*)$ testing/index.php/$1 [L]
If your host requires forcing query strings, try adding a question mark following index.php in the RewriteRule line above, like so:
RewriteRule ^(.*)$ /index.php?/$1 [L]
do you have apache rewrite-mod enable ?
you must have apache rewrite-mod enabled to do that ..
Check your config at apache configuration path ..
Try this
RewriteEngine on
RewriteCond $1 !^(index\.php|resources|robots\.txt)
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php/$1 [L,QSA]
change $config['index_page'] = 'index.php'
to
$config['index_page'] = ''
from
application\config\config.php
Also check your apache config for mod rewrite is enabled or not.
Checking URl Rewrite is Working or Not
MOD Rewrite
$isTrue = in_array('mod_rewrite', apache_get_modules());
Unfortunately, you're most likely trying to do this with CGI, which makes it a little bit more difficult.
You can test it using the following, though
$isTrue = strpos(shell_exec('/usr/local/apache/bin/apachectl -l'), 'mod_rewrite') !== false
If the above evaulates to true, then mod_write is enabled.
You are using the rewrite engine of apache. Make sure mod_rewrite is enabled and make sure your regular expression fulfills your needs.
Read about mod_rewrite here.
The htaccess rules look OK. Because you havent shown your code its hard to say but its either one of the following:
Your having an issue with your controller and method both being called 'departments'. If this is true either try renaming the method to something other than 'departments' or getting rid of it all together.
You dont have a controller called 'departments' (it doesnt show in your directory structure) or a route to handle the URI 'departments'. Either create the controller or add a route to direct the URI 'departments' to the controller you want to use. ie:
$route['departments/departments']='an_existing_controller/an_existing_method';
You dont have a method called 'departments'. If this is true get rid of the additional URI component called 'departments' or create a new method (as above dont call your method the same thing as your controller).
In config.php (which is mostly loated in application/config/config.php
make index page value to empty string, like this,
$config['index_page'] = '';
In root folder of your application make a .htaccess file with following code,
<IfModule mod_rewrite.c>
RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php/$1 [L,QSA]
</IfModule>
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. :)
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.