codeigniter on xampp wants me to use index.php in uri - codeigniter

I have a problem with setting up a local testing environment using codeigniter and an already existing code.
Well, the problem is, that I can't open a page, without having "index.php" in my URL. So, "test.mydomain.local/index.php/search" works fine while "test.mydomain.local/search" does not. But all links in the code, excluding the action-URLs in form-tags, doesn't have this "index.php" in the URL.
How can I solve the problem, that codeigniter or the xampp need this "index.php" in the URL? Do I need to change something in my code or maybe in .htaccess?
Here is my config.php
$config['base_url'] = "http://test.mydomain.local/";
$config['index_page'] = "index.php";
$config['uri_protocol'] = "AUTO";
Well, this code forces the "index.php" in the action-URL in form tags. But actually I dont want to have this index.php in any URL. So that my config.php should look like this, I guess:
$config['base_url'] = "http://test.mydomain.local/";
$config['index_page'] = "";
$config['uri_protocol'] = "AUTO";
Here is the .htaccess
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
### force www
RewriteCond %{HTTP_HOST} ^mydomain.com [NC]
RewriteRule (.*) h t t p : / / w w w . m y d o m a i n . c o m/$1 [R=301,L]
RewriteCond %{HTTP_HOST} ^domain.local [NC]
RewriteRule (.*) h t t p : / / t e s t . d o m a i n . l o c a l/$1 [R=301,L]
### if the is not a request for an existing file or directory
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
### and the URI does not end with a /
RewriteCond %{REQUEST_URI} !^([^?]*)/($|\?)
### redirect and add the slash.
RewriteRule ^([^?]*) $1/ [L,R=301]
### if the is not a request for an existing file or directory
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
# rewrite to index.php passing the URI as a path, QSA will preserve the existing query string
RewriteRule ^(.*)$ index.php?/$1 [L,QSA]
</IfModule>
<IfModule !mod_rewrite.c>
# If we don't have mod_rewrite installed, all 404's
# can be sent to index.php, and everything works as normal.
# Submitted by: ElliotHaughin
ErrorDocument 404 /index.php
</IfModule>
Can anybody help me? It is driving me nuts!

I use xampp and have found this htaccess is best. Do not for get to put your base url in config/config.php and remove index.
.htaccess
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]
Your config.php
/*
|--------------------------------------------------------------------------
| Base Site URL
|--------------------------------------------------------------------------
|
| URL to your CodeIgniter root. Typically this will be your base URL,
| WITH a trailing slash:
|
| http://example.com/
|
| If this is not set then CodeIgniter will try guess the protocol, domain
| and path to your installation. However, you should always configure this
| explicitly and never rely on auto-guessing, especially in production
| environments.
|
*/
$config['base_url'] = 'http://localhost/project name/';
/*
|--------------------------------------------------------------------------
| Index File
|--------------------------------------------------------------------------
|
| Typically this will be your index.php file, unless you've renamed it to
| something else. If you are using mod_rewrite to remove the page set this
| variable so that it is blank.
|
*/
$config['index_page'] = '';

Related

CodeIgniter application links not working

I installed an application built with CodeIgniter on my local computer which has MAMP. The home page contains a bunch of links to other pages. Clicking any of the links doesn't do anything. The page just refreshes but the browser doesn't redirect. Looking at this piece of ducumentation, I think that the URI doesn't have any data and therefore it just goes back to the home page. What do I need to do to test this and fix it?
There are three reserved routes:
|
| $route['default_controller'] = 'welcome';
|
| This route indicates which controller class should be loaded if the
| URI contains no data. In the above example, the "welcome" class
| would be loaded.
change your .htaccess to Codeingiter's provide htaccess file below.
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php/$1 [L]
place that to your root application folder.
Set the base_url of your application in config.php to the same url you are using to access the website, it should be something like this:
$config['base_url'] = "http://localhost/your_app_directory_name";
It should work.
For .htaccess use this:
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php/$1 [L]

The requested URL was not found on this server' in XAMPP; Used Answers in Other Threads

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>

Remove index.php from Codeigniter URL in Wamp

I have big problem trying to remove index.php from url's
i have searched lots if forums (this also), but no help for my situation.
so i have config.php file
$config['base_url'] = '';
$config['index_page'] = '';
$config['uri_protocol'] = 'AUTO';
my .htaccess file in public_html folder near index.php.
RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule .* index.php/$0 [PT,L]
i have rewrite_module ON (and it's working) and my httpd.conf AllowOverride set to All
so when i am going to mydomain.com/controller/action - I get 404
but when i go to mydomain.com/index.php/controller/action - everything is OK..
i have tried lots of .htaccess examples... and so on.. nothing helps..
.htaccess (This should be place outside application folder)
Paste this
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php/$1 [L]
</IfModule>
Note : Sometime index.php will not remove in windows. But if you upload it to server it will work fine. This happen me too in XAMPP but if i upload it to host(Linux) it works fine
My Config which is working fine :
config.php
$config['base_url'] = '';
$config['index_page'] = '';
$config['uri_protocol'] = 'AUTO';
.htaccess
# 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]

How to remove index.php with Codeigniter in Godaddy.com

i built a website with codeigniter and when i uploaded it it give me that error The requested document was not found on this server. i know that the problem is with my .htaccess code. so anyone can help me?
RewriteEngine on
RewriteCond $1 !^(index\.php|css|js|robots\.txt|images|itempics)
RewriteRule ^(.*)$ /index.php/$1 [L]
Try this (anything listed in with the js|css etc will not use the rewrite
Options +FollowSymlinks
RewriteEngine on
# On Rackspace and getting 404's? Uncoment this by removing the # :
# RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
<IfModule mod_rewrite.c>
RewriteRule ^(.+)\.(\d+)\.(js|css|docs|img|invoices|support|demos|blog|devx)$ $1.$3 [L]
</IfModule>
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php?/$1 [L]
On one shared hosting I have this set:
RewriteEngine on
RewriteBase /
Options -Indexes
RewriteCond $1 !^(index\.php|robots\.txt|assets)
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php/\?$1 [L]
Also,
/*
|--------------------------------------------------------------------------
| Base Site URL
|--------------------------------------------------------------------------
|
| URL to your CodeIgniter root. Typically this will be your base URL,
| WITH a trailing slash:
|
| http://example.com/
|
| If this is not set then CodeIgniter will guess the protocol, domain and
| path to your installation.
|
*/
$config['base_url'] = 'http://example.tld/';
/*
|--------------------------------------------------------------------------
| Index File
|--------------------------------------------------------------------------
|
| Typically this will be your index.php file, unless you've renamed it to
| something else. If you are using mod_rewrite to remove the page set this
| variable so that it is blank.
|
*/
$config['index_page'] = '';

Page route CodeIgniter I

I am using a reference book called PHP and MVC with CodeIgniter, and I’m following the examples of projects putting in my personal pc.It runs fine at my local PC and but gives some error at webserver. Diagnosis: The problem in question is the routes of pages. in my personal pc works normally, but when I put it on the web server can not find the requested page.
http://orion.locadados.com.br/~wladi/Carrinho_Compras/
http://orion.locadados.com.br/~wladi/Carrinho_Compras/categoria/artigos-esportivos
The routes defined in my project are as default for any server, because they are in the project folder itself. Just do not put the line of code, it would not know which part of the code put online.
How can i fix this?
file .htaccess
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} -s [OR]
RewriteCond %{REQUEST_FILENAME} -l [OR]
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^.*$ - [NC,L]
RewriteRule ^.*$ index.php [NC,L]
the file routes.php
<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
/*
| -------------------------------------------------------------------------
| URI ROUTING
| -------------------------------------------------------------------------
| This file lets you re-map URI requests to specific controller functions.
|
| Typically there is a one-to-one relationship between a URL string
| and its corresponding controller class/method. The segments in a
| URL normally follow this pattern:
|
| example.com/class/method/id/
|
| In some instances, however, you may want to remap this relationship
| so that a different class/function is called than the one
| corresponding to the URL.
|
| Please see the user guide for complete details:
|
| http://codeigniter.com/user_guide/general/routing.html
|
| -------------------------------------------------------------------------
| RESERVED ROUTES
| -------------------------------------------------------------------------
|
| There area two reserved routes:
|
| $route['default_controller'] = 'welcome';
|
| This route indicates which controller class should be loaded if the
| URI contains no data. In the above example, the "welcome" class
| would be loaded.
|
| $route['404_override'] = 'errors/page_missing';
|
| This route will tell the Router what URI segments to use if those provided
| in the URL cannot be matched to a valid route.
|
*/
$route['default_controller'] = "home";
$route['categoria/(:any)'] = "home/categoria/$1";
$route['produto/(:any)'] = "produtos/detalhes_produto/$1";
$route['404_override'] = '';
/* End of file routes.php */
/* Location: ./application/config/routes.php */
try with this .htaccess:
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_URI} ^sys.*
RewriteRule ^(.*)$ /index.php?/$1 [L]
RewriteCond %{REQUEST_URI} ^app.*
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>
assuming that your system folder is sys and application folder is app
For me this htaccess works with the latest CI version
DirectoryIndex index.php
RewriteEngine on
RewriteCond $1 !^(index\.php|images|css|js|robots\.txt|favicon\.ico)
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ ./index.php/$1 [L,QSA]
Try with this

Resources