0

how to remove function controller in url with .htaccess.

example

www.domain.com/controller/function/variable

to

www.domain.com/controller/variable

i try write the .htaccess file like this

<IfModule mod_rewrite.c>
    RewriteEngine On
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteRule ^(.*)$ index.php/$1 [L] 

    RewriteRule ^index.php/catalog/([^./.]+)$ ./catalog/index/$1   
</IfModule>
<IfModule !mod_rewrite.c>
    ErrorDocument 404 index.php
</IfModule>

catalog is controller and index is function

but not works, it bring out the 404 page.

thanks.

2
  • depends on what you want to achieve, you can set the function as private. Commented Sep 12, 2014 at 10:36
  • 1
    It can also be done with config/routes.php. Commented Sep 12, 2014 at 10:38

3 Answers 3

1

You can solve this problem by CodeIgniter Routing

go to application/config/routes.php and write rout rules this way

$route['controller/(:any)'] = "controller/function/$1";

let your controller name article and function name details so you can write routing rules for this function following

$route['article/(:any)'] = "article/details/$1";

Hope it will help full for you.

Sign up to request clarification or add additional context in comments.

Comments

1

It can also be done using Codeigniter routing.

config/routes.php

$route['controller/(:any)'] = "controller/function/$1";

Comments

0

In this case you need to use routing directly in your framework. You probably need read this article.

https://ellislab.com/codeigniter/user-guide/general/routing.html

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.