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

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:




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!

You can set up "home" as your default controller and CI will redirect '/' to /home/index.

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

There is a redirect function in one of the CI helpers. Can't remember whcih, but it's there.

[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.

I know but I don't know the mod_rewrite to do it. Does anyone know the mod_rewrite to do this?

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

class Home_redirect {
   function Home_redirect(){
      $CI =& get_instance();
      if(count($CI->uri->segment_array()) == 0){


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

I would prefer to do this with mod_rewrite, keeping it as "clean" as possible.

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.

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