Codeigniter cannot access controller without index.php - php

My local xampp codeigniter projec's url was
http://localhost/ci_yudeesh/index.php
But then wanted to remove the index.php part from the url so I followed the steps given in the userguide.
After that i could access the project without index.php with the url
http://localhost/ci_yudeesh/
I have a controller named Home and I can access this using http://localhost/ci_yudeesh/index.php/home
, but when try to access this using http://localhost/ci_yudeesh/home it gives this error:
this is my config:
$config['base_url'] = 'http://localhost/ci_yudeesh/';
$config['index_page'] = '';
$config['uri_protocol'] = 'REQUEST_URI';
this is my .htaccess:
<IfModule authz_core_module>
Require all denied
</IfModule>
<IfModule !authz_core_module>
Deny from all
</IfModule>
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php/$1 [L]
this is my route:
$route['default_controller'] = 'Home';
$route['404_override'] = '';
$route['translate_uri_dashes'] = FALSE;
Can someone help me fixing this? I tried all the other answers to similar type questions but none worked.

Remove the .htaccess from the application folder and put it outside the application folder and written only the below code in it. If it not work then I will give you another .htaccess code.
RewriteEngine on
RewriteCond $1 !^(index\.php|resources|robots\.txt)
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php/$1 [L,QSA]

Change the .htaccess file . Remove the codes from the existing file and add the following codes on the file :-
RewriteEngine on
RewriteCond $1 !^(index.php|resources|robots.txt)
RewriteBase /ci_yudeesh/
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php?/$1 [L]

Related

Removing index.php from CodeIgniter URL

I'm struggling with removing the 'index.php' part of my CodeIgniter URL.
I'm using CodeIgniter version 3.1.2. I've followed all steps on other questions about this:
Changed $config['index_page'] = 'index.php' to $config['index_page'] = ''
Changed $config['uri_protocol'] = 'AUTO' to $config['uri_protocol'] = 'REQUEST_URI'
Added a .htaccess file in the root folder of my project with the following code:
RewriteEngine on
RewriteCond $1 !^(index\.php|resources|robots\.txt)
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php/$1 [L,QSA]
However when I try to access my site, I get the following error code.
Not Found
The requested URL /Toneel/Site/index was not found on this server.
The rewrite module is turned on in my Apache Server.
Can anyone help me out with this issue?
This setting worked for me.
$config['base_url'] = '';
$config['index_page'] = '';
$config['uri_protocol'] = 'REQUEST_URI';
.htaccess
<IfModule mod_rewrite.c>
RewriteEngine On
#RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^ index.php [QSA,L]
</IfModule>
To allow overriding htaccess in Apache Configuration you have to edit and change /apache2.conf file to
AllowOverride All
And restart server.
Try this code in .htaacess:
RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule .* index.php/$1 [PT,L]
Try this in your .htaccess file
RewriteEngine On
RewriteBase /yourfolderhere/
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php/$1 [L]
In my case, it works with:
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /project-name
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^ index.php [QSA,L]
</IfModule>
** Important, this should be in an .htaccess file in the root of your project.
In config should be like this:
$config['base_url'] = 'http://your-url-here/';
$config['index_page'] = '';

.htaccess file does not working on godaddy server

Can someone tell me why this code would work on my local server but not on godaddy server?
I get the following error on godaddy...
I have creating one codeigniter project and host on godaddy server but .htaccess file does not working
my problem is "https://www.tripbrip.com/index.php/home/app_view" this same url come in my url side but i want to remove index.php in this link
my directory structure is this:
Options +MultiViews
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^([^\.]+)$ index.php/?$1 [NC,L]
my config file:
$config['base_url'] = "https://".$_SERVER['HTTP_HOST'].'/';
$config['index_page'] = '';
$config['uri_protocol'] = 'REQUEST_URI';
This file run in my localhost but not working on server.
I have use many code but still problem remain same .
If I browse to http://example.com/bootstrap.php I get a 404 resource not available at /
Maybe u can try put this on your .htaccess
<IfModule mod_rewrite.c>
#RewriteEngine on
#RewriteBase /
#RewriteCond %{REQUEST_FILENAME} !-f
#RewriteCond %{REQUEST_FILENAME} !-d
#RewriteRule .* index.php/$1 [PT,L]
Options +FollowSymLinks
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^ index.php [L]
</IfModule>
And for your config file. maybe u can just empty it.
$config['base_url'] = '';
If still error, you can try this
$config['base_url'] = "http://".$_SERVER['HTTP_HOST'];
$config['base_url'] .= preg_replace('#/+$#', '', dirname($_SERVER['SCRIPT_NAME'])).'/';
The following setting works fine for me.
RewriteEngine on -MultiViews
Options All -Indexes
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
#RewriteRule ^(.*)$ index.php/$1 [L]
RewriteRule ^(.*)$ index.php?/$1 [QSA,L]
in application => config => config.php
$config['index_page'] = ''; // should be blank
instead of
$config['index_page'] = 'index.php';

Codeigniter remove /index.php from URL

Okay so I know that a lot of people have been asking the same or similar questions, but I don't seem to find a solution that works for my project. So please don't put this as a duplicate.
I have a website made with codeigniter. It was running just fine without the index.php in the url. So the rewrite was successfull. Until a few days ago: all of a sudden the admin area (/admin) returned a 404 and was only accessible by the path '/index.php/admin'. The rewrite code that once used to work didn't do a thing anymore.
And know I'm back at the start -> the problem is that I cannot delete the index.php from my url.
I tried so many things that I don't know what to do anymore.
The application is stored under 'public_html/application/...
The image below is inside the application folder where the .htaccess file and index.php are.
Is this the right location to change the .htaccess?
I tried rewriting the .htaccess but without success:
RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule .* index.php/$0 [PT,L]
RewriteEngine on
RewriteCond $1 !^(index\.php|public|\.txt)
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php?$1
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond $1 !^CI/(index\.php|public|images|robots\.txt|css)
RewriteRule ^(.*)$ /index.php/$1 [L]
RewriteEngine on
RewriteCond $1 !^(index\.php|images|robots|css\.txt)
RewriteRule ^(.*)$ /index.php/$1 [L]
My config file:
$config['base_url'] = 'http://www.mysite.be/';
$config['index_page'] = '';
$config['uri_protocol'] = 'AUTO';
Routes.php:
$route['default_controller'] = "c_home/index";
$route['404_override'] = '';
$route['admin'] = "c_home/adminpanel";
$route['logout'] = "c_login/logout";
Does anybody have a clue what is going on or how this can be fixed?
Thanks in advance!
The .htaccess should be in the public_html directory -- ie: one level up from the current location.
The index.php is presumably in public_html already and
The index.* you have in the picture is index.html -- as it should be.
If .htaccess is in the right place per the above, then this .htaccess code will work:
RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php?/$1 [L]
So I have been messing around with this and finally made it work
For this I made changes to the htaccess and controllers.
I changed the admin function to a new controller and changed this in the routes.php
new routing
$route['admin'] = "c_login/index";
new .htaccess
RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule .* index.php/$0 [PT,L]
Try set
$config['uri_protocol'] = 'PATH_INFO'
And set
$config['enable_query_strings'] = FALSE;
If we need a remove /index.php from url in codeigniter
Than
application/config/config.php
$config['index_page'] = '';
$config['uri_protocol'] = 'REQUEST_URI';
add .htaccess file at root directory of project
RewriteEngine on
RewriteBase /[Your project folder name]/
RewriteCond $1 !^(index.php|resources|robots.txt)
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php/$1 [L,QSA]
Now you can access like
http://example.com/controller/method
May it's helpfull for you
I don't know what the heck you're doing with all that code, but I just put this in my .htaccess file:
RewriteRule ^(.*)$ /index.php?/$1 [L]
And boom.

cannot get rid of index.php from url in CodeIgniter

I'm new to CodeIgniter and I'm trying to figure out why the standard methods that I have seen both on the codeigniter site and here on SO aren't working for me to get rid of index.php from the url in my project.
I'm running CentOs, and the path to my project looks like:
/var/www/html/myproject
I have made sure that mod_rewrite is enabled in httpd.conf by checking via phpinfo()
My .htacess file looks like this:
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /myproject/
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
</IfModule>
my config.php looks like this (I have also tried PATH_INFO and REQUEST_URI for uri_protocol):
$config['base_url'] = 'http://localhost/myproject/';
$config['index_page'] = '';
$config['uri_protocol'] = 'AUTO';
My routes.php looks like this:
$route['default_controller'] = "site";
$route['404_override'] = '';
$route['site/price/(.*)'] = "site/price/$1";
The signature for the site controller's price action is this:
public function price($a, $b, $c) {
//code
}
When I go to
http://localhost/myproject/index.php/site/price/32137/2/1
the price function is reached successfully, but when I try
http://localhost/myproject/site/price/32137/2/1
I get an error page saying
The requested URL /myproject/site/price/32137/2/1 was not found on this server.
Am I missing something?
Thanks in advance
EDIT:
If it's any help, I can get to my project's site/index method with just the url: localhost/myproject but none of the other actions appear reachable.
RewriteEngine On
RewriteBase /myproject/
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ /index.php/$1 [L]
Use the exact .htaccess mod_rewrite config provided in the docs for Codeigniter
RewriteEngine on
RewriteCond $1 !^(index\.php|images|robots\.txt)
RewriteRule ^(.*)$ /index.php/$1 [L]
Works for me every time.
There are 2 parts to removing index.php from the url:
1) Tell .htaccess to route around index.php. Something like this:
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ /index.php?/$1 [L]
2) Edit your system/cms/config/config.php configuration file and update this setting from:
$config['index_page'] = 'index.php';
to
$config['index_page'] = '';
Here's a sample .htaccess file I use:
<IfModule mod_rewrite.c>
Options +FollowSymLinks -Indexes
RewriteEngine On
# Keep people out of codeigniter directory and Mercurial data
RedirectMatch 403 ^/(/codeigniter|\.git|\.hg).*$
#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} ^codeigniter.*
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>
ErrorDocument 404 public/index.php
</IfModule>
how about this
.htaccess
RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule .* index.php/$0 [PT,L]

Want to remove Index.php from Codigniter URL

I want to remove index.php from code igniter URL ,I had created .htaccess file and stored it in application folder parallel to index.php and also remove
$config['index_page'] = '';
from config.php.
Code in .htaccess file, which is not working :
RewriteEngine on
RewriteCond $1 !^(index\.php|images|css|js|robots\.txt)
RewriteRule ^(.*)$ /WCPM/index.php/$1 [L]
URL of the project is:
localhost/WCPM/index.php
NOTE:Please Don't mark this question as duplicate because I had already tried lots of solution for the same but none of them works for me , so at last I am asking this question here for the solution
In Config.php Change as Follows
$config['index_page'] = '';
$config['base_url'] = 'http://localhost/WCPM/';
And Create .htaccess file like
RewriteEngine on
RewriteCond $1 !^(index\.php|[WCPM])
RewriteRule ^(.*)$ /WCPM/index.php/$1 [L]
and Save this in Root Folder [WCPM] i.e. near Application Folder.
For More Details Refer the CI Manual # http://ellislab.com/codeigniter/user-guide/general/urls.html
Enable mod_rewrite module in apache.
If that doesnt work or mod_rewrite is already enabled, try this
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php?/$1 [L]
</IfModule>
First of all, change following setting in your config file.
$config['index_page'] = '';
and then, replace .htaccess file located at your project root folder not in the application folder with the following code..
RewriteEngine on
RewriteCond $1 !^(index\.php|public|\.txt)
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php?$1
There is a full article for this at:
http://www.web-and-development.com/codeigniter-remove-index-php-minimize-url/#remove-index-php
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond $1 !^(index\.php|imgs)
RewriteRule ^(.*)$ index.php/$1 [L]
RewriteRule ^media/imatges/([0-9]+)/([A-Za-z0-9-]+).jpg?$ imgs/$1 [T=image/jpeg,L]
<Files "index.php">
AcceptPathInfo On
</Files>
This is the entire recommended code to put at the start of your .htaccess file

Categories