I have a little problem with codeigniter and the default controller behavior.
My CI resides in a subdir on the development environment at localhost/web/new_info and the same path for production like 192.168.30.108/web/new_info.
Always when calling the url like
localhost/web/new_info/welcome
the page takes me to the server root, e.g. localhost/.
But I can call the "welcome" controller via:
localhost/web/new_info/
localhost/web/new_info/index.php/welcome
and I can call welcome's methods as well like
localhost/web/new_info/welcome/logout
There is another subdir in my controllers called settings and contains another welcome.php intself. I can access this controller directly without problems and the page stays there
localhost/web/new_info/settings/welcome
There is .htaccess and mod_rewrite set up according to
http://www.farinspace.com/codeigniter-htaccess-file/.
.htaccess
SetEnvIf Host 192.168.30.108$ CI_ENV=production
SetEnvIf Host localhost$ CI_ENV=development
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /web/new_info/
RewriteRule ^(welcome(/index)?|index(\.php)?)/?$ / [L,R=301]
RewriteRule ^(.*)/index/?$ $1 [L,R=301]
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.+)/$ $1 [L,R=301]
RewriteCond %{REQUEST_URI} ^system.*
RewriteRule ^(.*)$ /index.php/$1 [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php/$1 [L]
</IfModule>
<IfModule !mod_rewrite.c>
ErrorDocument 404 /index.php
</IfModule>
in config/development/config.php I have
...
$config['base_url'] = 'http://localhost/web/new_info/';
$config['index_page'] = '';
...
and generic routes
$route['default_controller'] = 'welcome';
$route['404_override'] = '';
$route['translate_uri_dashes'] = FALSE;
Xampp and the real server running apache2 act the same way. Even after completely disabling mod_rewrite and calling the welcome controller redirects to server root.
Currently I am using CI 3.0.3 and tested with the latest 3.0.6 as well with the same behavior.
What I want is to call localhost/web/new_info/welcome and stay there..
Thank you!
Ok, found out by myself.. dumb copy paste of .htaccess.
Namely the line
RewriteRule ^(welcome(/index)?|index(\.php)?)/?$ / [L,R=301]
has to be
RewriteRule ^(welcome(/index)?|index(\.php)?)/?$ /web/new_info/ [L,R=301]
in my case. The author of the htaccess file didn't mention it on his page.
But changing the htaccess file only did not help. I had to completely restart my session, otherwise changes were not applied. It's a bit unusual for me, I thought changes in this file were instant.
Nevertheless, it's fine now.
Related
I am using the latest version of CodeIgniter and XAMPP. I have searched stackoverflow and followed te suggestion from other threads with the same problem, to no avail.
I have several CI projects running oin my localhost b(each with their own CI install). I recently started a new project and went through the following steps to remove index.php from appearing in the URL:
Changed $config['index_page'] = "index.php" to
$config['index_page'] = '' in config.php
Changed $config['uri_protocol'] = "AUTO" to
$config['uri_protocol'] = "REQUEST_URI" in config.php.
Updated the .htaccess file to the following:
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php/$1 [L]
</IfModule>
Restarted apache
Yet I am still getting this error.
I have confirmed that mod_rewrite is installed in my XAMPP config. Plus, I am using rewrite rules for the other projects on my locolhost and they are working fine. I also made sure that update the base_url in the config: $config['base_url'] = 'http://'.$_SERVER['HTTP_HOST'].'/folder_name';
I have tried variations on the .htaccess file that I have found in other answers, yet an still at a loss. I've done this before; what's different!?
EDIT: I am only getting this error when trying to explicitly go to a controller/method. I have the default controller set to my login controller, so going to http://localhost/folder_name correctly hits the Login/login() controller/method. However, if I change the url to go to http://localhost/folder_name/login/login, I get the 404 error. However, http://localhost/folder_name/index.php/login/login/ eorks just fine still.
I my self use XAMPP. and windows 10
Inside your project folder place the htaccess
htdocs > folder_name
htdocs > folder_name > .htaccess
Here is one I use
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]
Then on the config.php
| URL to your CodeIgniter root. Typically this will be your base URL,
| WITH a trailing slash:
|
| http://example.com/
$config['base_url'] = 'http://localhost/folder_name/';
$config['index_page'] = '';
Some case you will need to make sure you have the class and filename set where only the first letter is upper case. Explained here naming classes and here filenames
Add RewriteBase with your project folder name.
Change your .htaccess to
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /project_folder_name
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php/$1 [L]
</IfModule>
My apps url is
http://localhost/myapp/admin/index.php/projects
and I want to rewrite it as
http://localhost/myapp/admin/projects
I followed user guide
RewriteEngine on
RewriteCond $1 !^(index\.php|images|robots\.txt)
RewriteRule ^(.*)$ /index.php/$1 [L]
for this but not work for me.
Please follow these steps:
1- If you work on localhost please enable mode_rewrite in php.ini
2- Create a .htaccess file under project folder and paste this (please change 'project' to your project folder name):
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ /project/index.php/$1 [L]
</IfModule>
<IfModule !mod_rewrite.c>
ErrorDocument 404 /project/index.php
</IfModule>
3- Edit this line at application/config.php:
$config['index_page'] = "";
Thank /* ActuallyMAB */: Your code actually works. The above code works on localhost (WAMP Server on windows).
If you have placed your codeigniter project in some folder such as your directory structure looks like:
C:\wamp\www\proposal
So, You have to replace
RewriteRule ^(.*)$ /project/index.php/$1 [L]
to
RewriteRule ^(.*)$ /proposal{or your folder name}/index.php/$1 [L]
if this is not the case with your project {you have put your codeigniter directly into www folder}, then remove the folder name from the above code as it looks like;
RewriteRule ^(.*)$ /index.php/$1 [L]
also do not forget to change
$config['index_page'] = 'index.php';
to
$config['index_page'] = '';
in your config folder {config.php}
I hope others have also provided the same answer, but since the above code works in my project and i felt to provide some details too.
Has anybody in the history of the internet and web development, been able to get rid of the "index.php" with mod_rewrite in codeIgniter.
I've been trying for several days now and nothing seems to work.
I'm using this one (in .htaccess file):
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_URI} ^system.*
RewriteRule ^(.*)$ /index.php?/$1 [L]
RewriteCond %{REQUEST_URI} ^application.*
RewriteRule ^(.*)$ /index.php?/$1 [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php?/$1 [L]
</IfModule>
<IfModule !mod_rewrite.c>
ErrorDocument 404 /index.php
</IfModule>
Not sure where I got it but it works for my codeigniter install, local and live. Don't forget to set $config['index_page'] = ''; in your config file.
For mod_rewrite use the following in your .htaccess file
RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ /index.php/$1 [L]
If your codeigniter instance is running in a subdirectory then use the rewrite base command before the RewriteRule
RewriteBase /subdirectory/
Then set
$config['index_page'] = '';
In the config file.
You might have your .htaccess file in the wrong place. CodeIgniter has a default .htaccess placed in the applications folder, which I mistakenly took for the one I should edit.
You actually need to create a new .htaccess under the root folder. So not code_igniter/applications/.htacces...but code_igniter/.htaccess
Hope this helps.
Yes, I configured it under Linux using the instructions from here. However, I configured it via httpd.conf instead of using .htaccess.
I have used the settings provided above and they always worked - unless I did not have mod_rewrite enabled.
If you are having issues check to ensure you have mod_rewrite enabled. If you do not it will not matter what you put into .htacess or your Apache config
I am working on a fairly new install of CodeIgniter 2.0.
I have a htaccess-file containg this code
RewriteEngine on
RewriteCond $1 !^(index\.php|images|robots\.txt)
RewriteRule ^(.*)$ /index.php/$1 [L]
Going to the URL http://www.estiem.no/ESTIEM/CI/ works,
but http://www.estiem.no/ESTIEM/CI/site/index does not. It gives a 404. The controller Site exists, and contains the method 'index'
Any ideas what might be wrong?
You need to remove / from index.php
RewriteRule ^(.*)$ index.php/$1 [L]
It is a htaccess problem, back when everyone passed that code around we found that a lot of hosts didn't like it and you could hack it with a ? or this or that until it ended up looking like a jigsaw puzzle (the condition that is) but using a brilliant htaccess (not sure who the first was but like 500 have taken credit) you will never have to change it again (well not never but it will work 99% of the time un edited):
# Customized error messages.
ErrorDocument 404 /index.php
# Set the default handler.
DirectoryIndex index.php
# Various rewrite rules.
<IfModule mod_rewrite.c>
RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php/$1 [L,QSA]
</IfModule>
Trust me I have had the same issues and spend hours on google when i should have come here or even the CI wiki (since that is the first place I seen it), you would not believe how many issues are solved in CI with just that bit of htaccess. they really should add it to the repo.
I just noticed that since you have your CI install in a subfolder, you need to account for that in the .htaccess rewrite:
/ESTIEM/CI/
So your .htaccess will look like:
RewriteEngine on
RewriteCond $1 !^(index\.php|images|robots\.txt)
RewriteRule ^(.*)$ /ESTIEM/CI/index.php/$1 [L]
That should fix it (sorry late edit, due to #BrianOrtiz 's comment)
Try to access the controller with: localhost/site/index.php/controller
If that does not work maybe because the CI is case sensitive
localhost/site/controller == c:...\site\controller.php
localhost/SITE/controller == c:...\SITE\controller.php
else
<?php
controller Mycontroller extends Controller {
}
?>
will be named mycontroller.php in the controllers folder
If all else fails replace your htaccess by this:
RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule .* index.php/$0 [PT,L]
Hi everyone I'm having some problems when removing index.php in CodeIgniter.
I created my application locally and it works fine but when I uploaded it, removing index.php doesn't seem to work.
I have a feeling this could have something to do with my host, it's not the best and I've had problems before. It's hosted on Fatcow.
So..
all my CodeIgniter files are located in a sub-dirctory called outfitr. e.g
<root>/outfitr/
I have my .htaccess file located in this folder with the following taken from the CI wiki:
EDITED
RewriteEngine On
RewriteBase /outfitr/
RewriteCond %{REQUEST_URI} ^system.*
RewriteRule ^(.*)$ /index.php?/$1 [L]
RewriteCond %{REQUEST_URI} ^application.*
RewriteRule ^(.*)$ /index.php?/$1 [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php?/$1 [L]
changes fo my config.php look like the following. I have enabled query strings as I need them for a section of my application.
$config['base_url'] = "<host>.com/outfitr/";
$config['index_page'] = "";
...
$config['uri_protocol'] = "PATH_INFO";
$config['enable_query_strings'] = TRUE;
Any help would be great. As I said I think it might have something to do with the host Fatcow.
I have tested mod_rewrite, following the steps on the following page and it seems to be enabled.
http://www.wallpaperama.com/forums/how-to-test-check-if-mod-rewrite-is-enabled-t40.html
ok so after some trial and error I finally got it working. I setup my .htaccess file as follows. Note the '?' in RewriteRule.
RewriteEngine On
RewriteBase /outfitr/
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php?$1 [L]
Then in config.php I set
$config['uri_protocol'] = 'REQUEST_URI';
Think this is down to the way some hosts setup their mod_rewrite module. Dreamhost and hostgator have the same problem.
http://codeigniter.com/wiki/mod_rewrite/
If your installation is not in the server root you will need to amend the RewriteBase line from “RewriteBase /” to “RewriteBase /folder/”
The current .htaccess you have is re-routing all requests to /index.php, which as you said yourself is not there. You want them to route to /outfitr/index.php.
You can do this by changing the RewriteBase /outfitr/
If not, please give more detail.