http://localhost/codeigniter/index.php/user/main_page
how can you remove index.php from this url ?
Try this file. I use it in my projects
https://github.com/eborio/curso-de-codeigniter/tree/master/02-primeros-pasos
The answer is in the post that this question is ducplicated of.
This is the answer
Sean Vieira's answer:
If you are using Apache place a .htaccess file in your root web
directory containing the following:
RewriteEngine on
RewriteCond $1 !^(index\.php|[Javascript / CSS / Image root Folder name(s)]|robots\.txt)
RewriteRule ^(.*)$ /index.php/$1 [L]
Another good version is located here:
http://snipplr.com/view/5966/codeigniter-htaccess/
Try this:
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php/$1 [L]
Replace:
$config['index_page'] = "index.php"
to
$config['index_page'] = ""
if it still not work try to replace:
$config['uri_protocol'] = "AUTO"
//replace with the below code
$config['uri_protocol'] = "REQUEST_URI"
for more details: http://w3code.in/2015/09/how-to-remove-index-php-file-from-codeigniter-url/ check this
Related
My site http://www.bishal.prtia.com/prT_base/ throw an 404 error while loading in the server.
It works perfectly in the localhost. I tried changing everything that mentioned in this forum like changing .htaccess to web.config and changing base url routing config etc but it still throws an error.
Check the following things once again:
Make sure your base_url is proper as per your website address, not localhost
Check routes.php file for default controller and make sure it is correct.
Make sure .htaccess looks like
RewriteEngine on
RewriteCond $1 !^(index\.php|assets|images|js|css|upload|favicon.png)
RewriteCond %(REQUEST_FILENAME) !-f
RewriteCond %(REQUEST_FILENAME) !-d
RewriteRule ^(.*)$ ./index.php/$1 [L]
Then check following thigs:
Config.php
$config['base_url'] = 'http://www.bishal.prtia.com/prT_base/';
$config['index_page'] = '';
$config['uri_protocol'] = 'REQUEST_URI';
Routes.php
$route['default_controller'] = 'your controller name (like welcome)';
$route['404_override'] = '';
$route['translate_uri_dashes'] = FALSE;
Make sure php file name of controller start with capital letter like Welcome and also inside that file as well when inherit from CI_Controller
Function inside Welcome.php:
public function index()
{
$this->load->view('your view file');
}
Thanks
You need to do few steps.
Update base_url in config.php
Update RewriteBase in .htaccess
Set Permissions
if still not workable, add error_reporting(E_ALL) in index.php and see what it says
I also faced this error. I changed my .htaccess file [WORKED FOR ME] :-
.htaccess for Live Server :-
DirectoryIndex index.php
RewriteEngine on
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond $1 !^(index\.php|robots\.txt)
RewriteRule ^(.*)$ index.php?/$1 [L]
.htaccess for Localhost :-
RewriteEngine On
#RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule (.*) index.php/$1
I am running Apache 2.2.22 on Ubuntu 12.04.3 (Oracle VM on Windows 8.1).
Using the PHP phpinfo() function I see mod_rewrite in the apache2handler section under Loaded Modules, so mod_rewrite is enabled.
I made the following changes to my CI config file (application/config/config.php),
$config['index_page'] = 'index.php'; to: $config['index_page'] = '';
$config['uri_protocol'] = 'AUTO'; to: $config['uri_protocol'] = 'PATH_INFO';
I have tried numerous versions this(.htaccess file located in the root directory of CI ):
RewriteEngine on
RewriteCond $1 !^(index\.php|images|robots\.txt)
RewriteRule ^(.*)$ /index.php/$1 [L]
but have yet to get it to work.
What else am I missing here?
This worked!
RewriteEngine On
RewriteBase /testsite/
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php/$1 [L]
Working on the assumption that your folder structure is something like... /var/www/html/testsite and your url is localhost/testsite, then the above rewrite rule will be looking for index.php in /var/www/html and not /var/www/html/testsite.
( /var/www/html will be the default document root. )
So in your equivalent folder of /var/www/html/testsite you can try using the following in your .htaccess file located in /var/www/html/testsite/. so you'd have /var/www/html/testsite/.htaccess with the code...
RewriteEngine on
RewriteCond $1 !^(index\.php|images|robots\.txt)
RewriteRule ^(.*)$ index.php/$1 [L]
All I have done is removed the leading / in the rewrite rule in the last line so it's not heading back to the default document root.
I know there are many issues like this but I applied everything and I don't find the correct way to do it.
The .htaccess is :
RewriteEngine On
RewriteBase /NewWebsite
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ /index.php/$1 [L]
</IfModule>
<IfModule !mod_rewrite.c>
ErrorDocument 404 /NewWebsite/error.php
</IfModule>
In config/config.php :
$config['base_url'] = 'https://mydomain.com/NewWebsite/';
$config['index_page'] = '';
$config['uri_protocol'] = 'AUTO'; // I change it with REQUEST_URI and PATH_INFO but it don't work
In server, mod_rewrite is enabled.
In localhost, everything is ok but when i uploaded it to the server, only index works (the first page that you see) but when I want to "move" around the web, i have 404 error, page not found.
I am going to show one controller and how I call it to change to another views.
class Products_controller extends CI_Controller {
public function index()
{
$this->load->helper('url');
$this->load->helper('html');
$this->load->view('products.php');
}
}
And from index, I call it:
echo base_url('Products_controller/index');
OR
echo base_url('Products'); // I have in config/routes.php ---> $route['Products'] = "Products_controller/index";
Anyone can help me? What am I missing ?
Thanks.
Though .htaccess depends on hosting server sometimes but you can try with this and let us know. Replace your .htaccess code with the following code:
RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*) index.php?/$1
Thats it.
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /NewWebsite/index.php [L]
</IfModule>
The above should work - make sure your .htaccess is inside the sub-directory you want to run from.
Also make sure that you don't have a conflicting .htaccess rule in the base directory.
And finally, I got a solution about this topic.It was not about a .htaccess problem, was a really dump and simple mistake.
In CodeIgniter, the name of the controllers and the name of the file
have to have exactly the same name. I have been defining my
controllers with the first letter capitalized and not in the file
name. And now it is everything ok !
Thank you guys.
I have a problem....I removed index.php from url...So ma route is :
$route['default_controller'] = "pages/show/index";
$route['photo'] = "pages/show/photo";
$config['base_url'] = 'http://localhost/blogCI/';
If I write in browser : localhost/blogCI/photo doesn't work, but if I write localhost/blogCI/index.php/photo it's work...
I have a .htaccess in root:
RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php/$1 [L]
I use apache and mod rewrite is actived and in my config
$config['index_page'] = '';
$config['uri_protocol'] = 'REQUEST_URI';
Everything is normal but I don't understand where is the problem...Help me guys please!!!!!!!!!!!
Won't work in a subfolder.
Create virtual host if you need CI to be located in that folder or move it to www root.
I am using CI 2.1.4 (trying to use) when I edit .htaccess to remove the index.php from my url it doesn't work. My project is inside a subfolder:
http://myserver.dev/project/
I've set the base_url removed the index.php from $config['index_page'] = '' and pasted the exact code form http://ellislab.com/codeigniter/user-guide/general/urls.html:
RewriteEngine on
RewriteCond $1 !^(index\.php|images|robots\.txt)
RewriteRule ^(.*)$ /index.php/$1 [L]
Tried some solutions (some using RewriteBase) from stackoverflow.com fellows, but, it doesn't work.
How can I fix that?
I dont think it's because of the .htaccess, this works for me and not because of the subfolder either.
This is an example of the .htaccess I'm using :
RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond $1 !^/(index\.php|assets/|humans\.txt)
RewriteRule ^(.*)$ index.php/$1 [L]
Set the right url in the base_url or this :
$config['base_url'] = 'http' . ((isset($_SERVER['HTTPS']) && $_SERVER['HTTPS'] == 'on') ? 's' : '')
.'://'.$_SERVER['HTTP_HOST'].str_replace('//','/',dirname($_SERVER['SCRIPT_NAME']).'/');
And obviously :
$config['index_page'] = '';
With this, it works for me...