1

Hi everyone I am having a problem in setting up the .htaccess URL fix for CodeIgniter Framework.

I have a site launched in a folder named "sites".

=> THE PROBLEM:

**This URL works perfectly:

http://127.0.0.1/sites/home/index/test

I want to get rid of /index/ from the URL

The destination URL should be like this:

http://127.0.0.1/sites/home/test

How can i acheive this URL?

Additional Info:

I have URL helper in autoload done which works great and here is the code in My Controller

class Home extends CI_Controller {

public function index($var='')
{
   echo $var; //outputs -> test
}

}

.htaccess

RewriteEngine on

RewriteCond $1 !^(index\.php|images|robots\.txt)
RewriteBase /sites
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule .* index.php/$0 [PT,L]
RewriteRule ^(.*)$ index.php/$1 [L]
1
  • Check Youn's answer below. You will need to create a catch all route. This will catch all requests to the home controller and re-route them to the index() method. Commented May 1, 2013 at 3:09

1 Answer 1

2

To do that, you want to add a route in config/routes.php:

route['home/(:any)'] = "home/index";

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

2 Comments

In order to make the variable accessible via the index() functions parameters you could even do: route['home/(:any)'] = "home/index/$1";
WOW! this is exactly what I needed, it worked like a charm! its a simple and efficient solution. Thank you Buddy!

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.