Liki Crus
Liki Crus

Reputation: 2062

How to change the codeigniter's URL using .htaccess file

I'd like to know how to do the URL rewriting using .htaccess file. My web application is based on PHP CodeIgniter and I am going to implement the SEF function.

Current URL is

http://localhost/index.php/sale/list

In this URL, "sale" is a controller name and "list" is a method name. I'd like to replace the URL with http://localhost/index.php/product-sales/list

I would think this can be done easily with .htaccess file if you know .htaccess well.

Thanks for your attention and time. Regards,

Upvotes: 0

Views: 376

Answers (2)

Zillur Rahaman Opu
Zillur Rahaman Opu

Reputation: 83

All routing is defined in route.php file.

Navigate to your project. Open application/config/routes.php file.

$route['sale/list'] = 'product-sales/list/';

Upvotes: 0

Mikeyhun
Mikeyhun

Reputation: 256

Put this into your .htaccess file and will rewrite everything that's index.php/sale/... to index.php/product-sales/...

RewriteEngine on

RewriteRule ^index\.php/sale/(.+)$ index.php/product-sales/$1 [R=301,L]

BUT I agree with @Daniel that it might be better to fix it in system rather than in htaccess

Edit: if i understand it right now, you just want to have a new url for the same controller so after you added the upper rule to your htaccess (so you redirect the old url's to the new one) you still need to add the new routes to the routes file like:

$route['product-sales/(:any)'] = 'sale/$1';

It should work now, if that's not the desired effect then explain more pls...

Upvotes: 1

Related Questions