81 responses to “CodeIgniter htaccess”

  1. Kyle

    Really helpful, thanks.

  2. juandelacruz

    Nice. This is something to try on…

  3. Jeremy Blake

    Dude, most of your blog posts are way over my head. I need to read your blog more. I might learn something important! Keep it up.

  4. marcello

    hi, you forgot /index.php/welcome is the same as / , but your solution doesn’t redirect it.

    can you provide some solution for this to be complete?
    I tried RewriteRule index\.php/(.*)$ $1 [L,R=301] (doesn’t work well)

    it works with /index.php/welcome, but there’s an infinite loop in things that doesn’t work, so it’s definitely not a good solution. Thank you

  5. David

    If you want to force trailing slashes then you can use this rule instead.

    # Forces trailing slashes (prevents SEO duplicate content issues)
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_URI} !/$
    RewriteRule ^(.+)$ $1/ [L,R=301]

  6. Jaap

    Hi, Thank you for this useful post.
    I implemented the .htacces file at one of my projects.

    But there is still one problem I think.
    It is still possible to request:
    http://www.domain.tld/index.php/controller

    Is there a way to remove the index.php?
    Thanks in advance!

  7. Jaap

    Sorry, I see the solution now, didnt read the comments ;)

  8. Chuck Lidderdale

    An annoying dupe problem. On a shared host my htaccess file contains
    RewriteCond %{HTTP_HOST} blackforest-co.com
    RewriteCond %{REQUEST_URI} !/blackforest/
    RewriteRule ^(.*)$ /blackforest/$1 [L]

    that works fine – except when one clicks on a link it comes back as:
    http://www.blackforest-co.com/blackforest/bfcc/ when it should be (which works)
    http://www.blackforest-co.com/bfcc/

    Just doesn’t look … clean. Any fix? Thanks

  9. Ra

    Really nice tutorial to keep in your bookmarks. Best about htaccess I have yet seen.

  10. Tzvook

    Hi
    .htacsess us still voodo to me :-(
    I got panalized by google fot this one:
    —————————
    Options +FollowSymLinks
    rewriteEngine on
    # Internally rewrite .my-domain.tv/ to my-domain.tv/pages//
    rewriteCond $1 !^pages/
    rewriteCond %{HTTP_HOST} !^www\.my-domain\.tv
    rewriteCond %{HTTP_HOST} ^([^.]+)\.my-domain\.tv
    rewriteRule (.*) /pages/%1/$1
    ————————————
    Do you see any reason for it in here ?

  11. Tzvook

    10X Dimas

  12. azifet

    Nice post there… however form data in the post variable $_POST gets lost whenever I redirect to the bootstrap file. any idea on how to work around this?

  13. alex

    tx for sharing this. I am using it for my first CI project which also holds a WordPress subfolder. So i can get some wp-posts in CI views.
    p
    But the default page url doesn’t work mydomain.com/?p=123
    should i edit the .htaccess.

    any suggestions,
    regards
    ps i have wp in /blog and in the end i like to have something blog/%custom%

  14. alex

    Hi Dimas,

    I think i am going to have a problem with CI + WP and SEO url’s/permalink, see my topic on http://codeigniter.com/forums/viewthread/147068/

    How would you bypass /blog/ and have the url request go to CI or WP???
    Hope i am making sence

    regards

  15. pit

    it works perfectly … comments are simple but very helpful … great job in fact!

    thanks!

  16. Asif Iqbal

    Hi,

    Nice post.. I am new in the Codeigniter and this post really helpful for me.

    Thanks mate.

  17. zeratool

    You can simplify that to this:
    #begin
    RewriteEngine On
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteRule ^(.*)$ /index.php/$1 [QSA,L]
    #end
    HTH

  18. Julio Bitencourt

    Dude! This definitely saved my life! Tks a lot!

  19. Nuno

    Hi Dimas, thanks for the nicely documented .htaccess
    We can learn a lot from documented code lines…

    I’m setting up my first complex CI project. It will be hosted at my job (public health care) and it will powerup our intranet and webapps.

    And now my question.
    I set up a ci_sys, a ci_app, and a ci_www at the same level. Then I setup an alias pointing to the ci_www and making it my public folder.
    # ci_app
    # ci_sys
    # ci_www
    # # index.php
    # # ci_assets
    # # # css
    # # # js
    # # # img
    So I basically set config file system_application to `../ci_sys` and aplication to `../ci_app`

    With your .htaccess, I’m redirected one folder up in my alias
    ex: base_url set to
    http://myhost/myCI/
    is redirected to
    http://myhost/

    Can you point me somewhere? Thanks

1 2 3 4