2

I have searched everywhere but i can't find appropriate result. I want to remove controller_name from every url of the site. My codeigniter is installed in subfolder of domain.

For Example:

www.site_name.com/subfolder/controller_name/any_method_name

I have only one controller from which i am calling all the methods.

I have learned that i have to do some changes in routes but i think that is only for one url. so, how to remove for every url.

2

3 Answers 3

0

Not sure if this works but you could try adding this in your application\config\routes.php:

$route['([a-z]+)'] = 'controller_name/$1';

The documentation https://www.codeigniter.com/userguide3/general/routing.html#regular-expressions

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

3 Comments

No, Its not working but i think this may be happen because i have installed my codeigniter in subfolder.
Other thing is, will it work for url which is redirecting from some other page?
Pratik Bhalodiya answer should work out in your case
0

Here, I am answering my own question. I have solved this problem by following solution.

Suppose, my controller name is users, then the answer is:

$route['^(:any)(/:any)?$'] = "users/$0";

This removes controller name from every url of the website.

1 Comment

that may give problem when site will in sub domain or sub folder
-1

Codeigniter support two types of routing rules

1)Wildcards

2)Regular Expressions

I prefer Wildcards

in routes just place this one

$route['login/(:any)'] = "v1/login";

A URL with "login" as the first segment, and anything in the second will be remapped to the "v1" class and the "login" method.

means your change www.abc.com/login instead of www.abc.com/v1/login

check it once routing in codeigniter here https://www.codeigniter.com/userguide3/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.