CodeIgniter Forums
CodeIgniter redirect problem - Printable Version

+- CodeIgniter Forums (https://forum.codeigniter.com)
+-- Forum: Archived Discussions (https://forum.codeigniter.com/forum-20.html)
+--- Forum: Archived General Discussion (https://forum.codeigniter.com/forum-21.html)
+--- Thread: CodeIgniter redirect problem (/thread-33034.html)



CodeIgniter redirect problem - El Forum - 08-13-2010

[eluser]Aerospace[/eluser]
When I go to http://www.hassanc.co.uk/home/ I get a 404 error. How can I make it so it redirects to http://www.hassanc.co.uk/home/index/ automatically? Is it something to do with the .htaccess file? Thanks for your help.


CodeIgniter redirect problem - El Forum - 08-13-2010

[eluser]cahva[/eluser]
Userguide is your friend:
http://ellislab.com/codeigniter/user-guide/general/urls.html


CodeIgniter redirect problem - El Forum - 08-13-2010

[eluser]Aerospace[/eluser]
I've done that already, index.php is removed from the URL, which is great. But I want it to go to www.hassanc.co.uk/home/index automatically when someone visits my CodeIgniter root installation (www.hassanc.co.uk/home). Thanks


CodeIgniter redirect problem - El Forum - 08-13-2010

[eluser]Suhas nazir[/eluser]
Hey u can simply remove index.php from ur url by using the following code.Copy the code and save it as .htaccess.Now u go to config.php and change it as $config['index_page'] = "";
RewriteEngine On
RewriteCond %{REQUEST_URI} ^/system.*
RewriteRule ^(.*)$ index.php?/$1 [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.+)$ index.php?/$1 [L]


CodeIgniter redirect problem - El Forum - 08-13-2010

[eluser]Georgi Budinov[/eluser]
Guys he wants something else ... He managed to remove the index.php already ...

@Aerospace

Paste this in the constructor of your home controller and should be ok

Code:
if($this->uri->total_segments()==1)
{
    $this->load->helper('url');
    redirect(current_url().'/index');
}



CodeIgniter redirect problem - El Forum - 08-13-2010

[eluser]Aerospace[/eluser]
[quote author="Georgi Budinov" date="1281731258"]Guys he wants something else ... He managed to remove the index.php already ...

@Aerospace

Paste this in the constructor of your home controller and should be ok

Code:
if($this->uri->total_segments()==1)
{
    $this->load->helper('url');
    redirect(current_url().'/index');
}
[/quote]

Now it goes to http://www.hassanc.co.uk/home/index/index Sad

I'm thinking about moving CodeIgniter to the root and then making a function called home() instead

But thanks for your help anyway Smile


CodeIgniter redirect problem - El Forum - 08-14-2010

[eluser]Aerospace[/eluser]
Yes! I got it to work by defining the default controller as 'index' in config/routes.php
How do I mark this thread as 'solved'?