81 responses to “CodeIgniter htaccess”

  1. Mehedi

    I host my website nibssolutions.
    First time my site work well.
    But this time it show many error.
    Help me.

  2. sonnt

    Very good, Thanks U

  3. Eduardo

    Pessoal, criei um site no Codeigniter e agora quero criar um blog vinculado a ele, ou seja, para ficar assim: http://www.meusite.com.br/blog. Alguém pode me dizer como posso fazer isso?

  4. Laurence Dawson

    These are some really handy tips, thanks!

  5. samantha
  6. rubena

    can anyone convert this to htaccess ?

    $clean_url = str_replace(‘index.php’,”,current_url());
    $current_url = ‘http://’.$_SERVER['HTTP_HOST'].$_SERVER['REQUEST_URI'];

    if($clean_url!==$current_url)
    {
    redirect($clean_url,’location’,301);
    }

  7. Nayan

    Please write some posts about , how to setup Smarty 3 with CI ..

  8. Adamantus

    I didn’t really learn anything from this but wanted to. I would have liked it if you had explained the code more. For example what does:

    RewriteRule (welcome(/index)? mean? What does the ? mean here? Does the (/index) imply what?

  9. Tom

    I’m getting some crawl errors in Google which point to a page that does not exisit on my website:

    http://www.example.com/?p=123
    What Rewritecond (or Redirect) script can I add to my .htaccess to redirect this to my homepage?

    Thanks
    Tom

  10. pit

    i’m not pro but it seems that something like this should work (untested) :
    RewriteRule ^\?p=[0-9]+$ / [L,R=301]
    reads :
    starting with
    the string “?p=” once
    followed with one or more Numeric character (between 0-9)
    that is last character
    then redirect 301 to home

    Not sure about the starting character, if it does not work, try
    RewriteRule ^p=[0-9]+$ / [L,R=301]
    Or
    RewriteRule ^.*\?p=[0-9]+$ / [L,R=301]

    hope it can help ^^

  11. Tom

    I tried each one but they all result in the message “Nothing found for ?p=168″
    Thanks for trying anyway

    Tom

  12. pit

    finally after some “live” testing and googling for help here’s the code that works for me :)

    RewriteEngine on
    RewriteBase /
    RewriteCond %{QUERY_STRING} ^p=[0-9]+$
    RewriteRule ^(.*)$ ? [R=301,L]
    ##OR: RewriteRule ^(.*)$ index.php? [R=301,L]
    ##where you can replace index.php with the landing page you want

    Hope this time it’ll work as you need ^^

  13. Tom

    That’s great, you’ve cracked it! Thanks & well done

    Tom

  14. Derk

    hi,

    First i want to say that this is the best ever topic about CI url routes and mod_rewrite.

    i have a question for my urls, they are like:
    http://example.com/username wich is working

    now this isnt working (im useing “alternative to get” for ci)
    http://example.com/home/var1:value1/var2:value2
    however this is working when:
    http://example.com/home/index/var1:value1/var2:value2

    is there away to remove the /index/ from my “alternative to get” urls?
    I have it all working for my /index.php/ and controller/index
    its working like controller/ wich i find usefull!

  15. Dennis

    Your explanation of how rewrite works was great and I can successfully implement it. However I loose my style sheet. This is the error I get:
    [client 127.0.0.1] client denied by server configuration:

    Anyone have any clues??

  16. Francisco

    Hi,

    I’m using CI 2.0.2. Where the app folder lives outside the system folder.

    On my hosting setup I have a subdomain.domain.com pointing to my root folder where the CI lives.

    I would like to use the URL to match an application folder. So let me explain.

    I have the following folder set up:
    Application1
    Application2
    System
    Index.php
    .htaccess

    I would like to use: subdomain.domain.com/application1/controller/method

    And the .htaccess rules to rewrite it to:
    Subdomain.domain.com/controller/method?app=application1

    So then in the index.php I could get hold of the $_GET['app'] to match the application folder.

    Could you help me with that rewriting rule?

    Thank you

  17. Hank

    I’ve set up your re-write but my url gets written with a question mark added in certain conditions.

    If I go to:
    http://domain.local/bla/bla

    It gets re-written as
    http://domain.local/?/bla/bla

    I’m rubbish at reg expression and alike.

  18. Hank

    Thanks for the reply.

    I’ve settled with:
    RewriteRule ^(welcome(/index)?|index(\.php))/$ / [L,R=301]
    RewriteRule ^(.*)/index/?$ $1 [L,R=301]

    The last ? has been removed from the first line.

    This works for:
    http://domain.local/controller/
    But not:
    http://domain.local/controller (note: the missing forward slash)

    Thanks.

  19. Hank

    I’m using the re-write that removes trailing slashes also.

    When I made reference to it working with:
    1. http://domain.local/controller/
    but not:
    2. http://domain.local/controller

    What I mean’t was, it successfully removes “controller/” leaving:
    http://domain.local
    Whereas 2. does not change.

    What should be added to remove “controller”?
    Thanks H