Codeigniter redirect repeats controller name in URL
- by Obay
This is my controller:
class Timesheet extends Controller {
...
function index() {
//loads view with a form that submits to "timesheet/change_date"
}
function summary() {
//loads view with a form that submits to "timesheet/change_week"
}
function change_date() {
...
redirect('timesheet');
}
function change_week() {
...
redirect('timesheet/summary');
}
...
}
The first form is located at http://localhost/dts/index.php/timesheet and when I submit the change_date form, it correctly goes thru the change_date() function and re-loads http://localhost/dts/index.php/timesheet correctly.
However, the second form is located at http://localhost/dts/index.php/timesheet/summary, and when I submit the change-week form, it goes thru the change_week() function but goes to http://localhost/dts/index.php/timesheet/timesheet/change_week. Notice the word timesheet is repeated. When I submit the form again, another timesheet is added.
What's wrong and how do I improve my code?
My .htaccess is below:
RewriteEngine on
RewriteCond $1 !^(index\.php|webroot|robots\.txt)
RewriteRule ^(.*)$ index.php/$1 [L]