Welcome Guest, Not a member yet? Register   Sign In
Redirect "/" to "/home"?
#1

[eluser]kyleect[/eluser]
I'm trying to figure out what to add to my htaccess to redirect "/" to "/home" but to complicate things, the app may not be in the root directory. It could be a sub directory, like this:

http://localhost/app/

to


http://localhost/app/home

I have tried looking at mod_rewrite tutorials but still can't get it to work. This is what I've tried.

RewriteRule ^/$ /home

Which, does nothing. Please help!
#2

[eluser]srisa[/eluser]
You can set up "home" as your default controller and CI will redirect '/' to /home/index.
#3

[eluser]kyleect[/eluser]
home is my default now, and that works but I want an actual redirect. This would be similar to how some people redirect www.domain.com to just domain.com
#4

[eluser]Unknown[/eluser]
There is a redirect function in one of the CI helpers. Can't remember whcih, but it's there.
#5

[eluser]Pascal Kriete[/eluser]
It's in the url helper (which is a good one to autoload Wink ).

Edit: Re-reading your post, for anything outside CI you will need to use mod_rewrite of course.
#6

[eluser]kyleect[/eluser]
I know but I don't know the mod_rewrite to do it. Does anyone know the mod_rewrite to do this?
#7

[eluser]darkhouse[/eluser]
I don't know if this would work, and this might be a "hacky" solution, but what if you wrote a library like this:

Code:
class Home_redirect {
  
   function Home_redirect(){
      $CI =& get_instance();
      %CI->load->helper('url');
      if(count($CI->uri->segment_array()) == 0){
         redirect('/home');
      }
   }

}

and then autoloaded that library? Again, I didn't test it, but it might do what you need without using mod_rewrite.
#8

[eluser]kyleect[/eluser]
I would prefer to do this with mod_rewrite, keeping it as "clean" as possible.
#9

[eluser]darkhouse[/eluser]
I agree it's a dirty solution and htaccess is the way to go (if possible). I would use this as a last resort myself.
#10

[eluser]garrettheel[/eluser]
Code:
RewriteEngine On
RewriteRule ^index.php$ /home [R]
The [R] at the end forces a visible redirect, rather than just loading /home and it still appearing as /. I assume this is what you want it to do, if not, just remove the [R]




Theme © iAndrew 2016 - Forum software by © MyBB