Question

This is my url of site:

xxx.myserver.net

In this site i want to routing the controller that means when i linkthis type url :

xxx.myserver.net/aaaaa

I want to redirect it into the controller which i desired taht means i want to redirect into :

xxx.myserver.net/index.php/controller-name/funation-name/aaaaa

I want to done this without using htaccess method only by using codeigniter uri routing method.

When i try to do this i get an error message :

Not Found

The requested URL  not found on this server.

This is the code i gave in the routes.php page:

$route['/(:any)'] = "xxx.myserver.net/index.php/controller-name/funation-name/$1";

What is the problem in my code?

How can i do this ?

Was it helpful?

Solution

You can't do that without using an .htaccess file. From a high level, the purpose of the .htaccess file is to route all requests to your domain through the CodeIgniter front controller, the index.php file in your root directory. Here is the documentation that explains how creating the .htaccess file and removing index.php from the URL works. To paraphrase, it states how arbitrary requests are treated as requests for the index.php file.

When you make a request to xxx.myserver.net/aaaaa the web server is searching for the resource aaaaa in your root. The request isn't even being processed by CodeIgniter. Since you have no resource titled aaaaa you are receiving an error.

To use CodeIgniter without an .htaccess file you'll need to pass each request through index.php. For example:

xxx.myserver.net/index.php/aaaaa

Then you could create your route like this:

$route['(:any)'] = 'controller_name/function_name/$1';

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top