0

My url link looked like:

http://localhost/CodeIgniter_2.1.2/index.php/pages/home

Then I wrote the .htaccess file using google as follows:

RewriteEngine on
RewriteCond $1 !^(index\.php|themes|images|robots\.txt)
RewriteRule ^(.*)$ index.php/$1 [L]

Now my link looks like:

http://localhost/CodeIgniter_2.1.2/pages/home

Now,I want to remove pages from this link. Can anyone help me figure this out?

So, my url could look like:

http://localhost/CodeIgniter_2.1.2/home

2 Answers 2

1

One way to do it is to create a custom route in the application/config/routes.php file, which routes the url 'http://localhost/CodeIgniter_2.1.2/home' to 'http://localhost/CodeIgniter_2.1.2/pages/home'

Custom routing is described here

The code will look something like:

$route['home'] = "pages/home";

EDIT

Your controller, method, and variable are named "pages", "view", and "home" respectively. Therefore, you should try the following route instead:

$route['home'] = "pages/view/home";

Also:

** Reserved Routes ** From the codeigniter documentation:

There are two reserved routes:

$route['default_controller'] = 'welcome';

This route indicates which controller class should be loaded if the URI contains no data, which will be the case when people load your root URL. In the above example, the "welcome" class would be loaded. You are encouraged to always have a default route otherwise a 404 page will appear by default.

Thus, you should not be setting the default controller to "pages/view/home." Rather, you should create an "index" method in the controller that defaults to the "home" view.

Also Don't forget to change the $config['index_page'] from 'index.php' to '' in the config.php file located in application/config/config.php.

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

3 Comments

What is the name of the controller and method you are trying to use to display the content for this URL? Is the controller named "pages" and the method called "home"?
controller is pages, method is view, and the attribute is home
$route['default_controller'] = 'pages/view/home'; $route['pages/(:any)'] = 'pages/view/$1'; $route['products/(:any)'] = 'new_/view/$1';
0

Try changing your rule so that the target is:

RewriteRule ^(.*)$ index.php/pages/$1 [L]

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.