Reputation: 147
I want to remove index from codeigniter URL which have parameters. Its not index.php but index function inside a controller. Currently my URL looks like this
www.example.com/app1/index/param1/param2
Here i wanna remove index from url so that URL would be
www.example.com/app1/param1/param2
If i do so now it shows me error as 404 probably because it searhces for function param1 inside app1 controller
Upvotes: 3
Views: 292
Reputation: 380
add route in application/config/routes.php
$route['app1/(:any)/(:any)'] = "app1/index/$1/$2";
use in the App1 class
:
public function index($param1, $param2) {
//do something
}
Upvotes: 0
Reputation: 9071
Hey please do following steps ,
application/config/config.php
$config['index_page'] = "index.php" to $config['index_page'] = ""
Root folder create .htaccess file
Note : Make sure create .htaccess
file not text file .
<IfModule mod_rewrite.c>
RewriteEngine On
#RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^ index.php [QSA,L]
</IfModule>
For working .htaccess file please download here http://wikisend.com/download/862912/.htaccess
Note : In some cases the default setting for uri_protocol does not work properly. Just replace
$config['uri_protocol'] ="AUTO" to $config['uri_protocol'] = "REQUEST_URI"
Coming to the routings :
Codeigniter support two types of routings i)Wildcards ii)Regular Expressions
I am giving you wildcards example please check bellow :
application/config/routes.php
place this line
$route['/app1/index/(:num)/(:num)'] = "/app1/$1/$1";
For more information please refer the official document http://www.codeigniter.com/userguide3/general/routing.html
Upvotes: 1
Reputation: 155
As your URL above, your controller looks like this:
<?php
class App1 extends CI_Controller
{
public function __construct()
{
parent::__construct();
}
public function index($param1, $param2)
{
// ...your code here
}
}
Try to change your controller again so you don't have to use index
as a function.
<?php
class Apps extends CI_Controller
{
public function __construct()
{
parent::__construct();
}
public function app1($param1, $param2)
{
// ... your code here
}
Upvotes: -1
Reputation: 3091
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php/$1 [L]
</IfModule>
try this .htaccess
if this code is not work then goto application/config/config.php
// Find the below code
$config['index_page'] = "index.php"
// Remove index.php
$config['index_page'] = ""
//and
// Find the below code
$config['uri_protocol'] = "AUTO"
// Replace it as
$config['uri_protocol'] = "REQUEST_URI"
i hope it will be helpful
Upvotes: 2