0

Please can any one suggest how to shorten the url

http://localhost:8080/MyWebApp/index.php/Cpanel_control/

to

http://localhost:8080/MyWebApp/Cpanel

in Codeigniter using routes.

I tried it in this way

$route['Cpanel'] = "MyWebApp/index/Cpanel_control";

But did not work

2 Answers 2

1

To remove index.php from your url in CI, you need .htaccess file. Check this out https://gist.github.com/philipptempel/4226750

I'm assuming Cpanel_control is a valid controller.

For the routing, you can have this in your routes settings

$route['Cpanel'] = "Cpanel_control";

To avoid any other issues, make sure base_url in config file is set thus

$config['base_url'] = "http://localhost:8080/MyWebApp";
Sign up to request clarification or add additional context in comments.

Comments

0

New Approach

Routing:

In some instances, however, you may want to remap this relationship so that a different class/method can be called instead of the one corresponding to the URL.

A short excerpt from the CI doc shows that you can't use routing here. Instead you should go for a mod_rewrite rule (.htaccess)

RewriteEngine On
RewriteRule ^index/Cpanel_control/(.*) Cpanel/$1 [R]

Old approach

According to the corresponding documentation, the paths are both not absolute. Furthermore, you need to set the "from"-URI as the array key and the "to" URI as the string. If you want to route index/Cpanel_control to Cpanel, you need to swap the URIs of you example.

So this would be correct:

$route['index/Cpanel_control'] = "Cpanel";

5 Comments

It gives me "The requested URL /MyWebApp/Cpanel was not found on this server" error.
@DilukshanMahendra Then check if your Cpanel-Controller exists/is configured correctly.
@DilukshanMahendra Then you misunderstood the concept of routing. What you want is a mod_rewrite via .htaccess!
@DilukshanMahendra Edited my answer for a new approach ;)

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.