Remove “index.php” from URL - Codeigniter

前端 未结 12 1180
清酒与你
清酒与你 2020-12-03 16:05

I\'ve looked in the documentation of Codeigniter of removing the index.php from the URL when accessing different views, the code shows how to remove it with apa

12条回答
  •  遥遥无期
    2020-12-03 16:28

    You all uri parts are rewrited, so it points to /index.php/code/home. The and good way to do it is to setup mapping eg. http://code.local to point to your /Users/~myusername~/Sites/code, then all your requests are resolved on the root level and everything will work as it should.

    EDIT: Downvoters seem to be ignorants, but nevermind..

    Here's what your code does now:

    GET http://localhost/code/home
    // rewritten to:
    http://localhost/index.php/code/home
    

    So like I said before the GOOD way would be host mapping so you get everything on the root level (which is GOOD as most likely you will have it this way on the production serv...) and that will do the trick withour changes in .htaccess.

    Otherwise you may use Francesco's advice with RewriteBase, but a bit changed:

    // Francesco's RewriteRule does this:
    http://localhost/code/home
    // rewritten to"
    http://localhost/code/index.php/code/home
    

    so simply change the RewriteRule to this:

    RewriteRule ^code/(.*)$ index.php?/$1 [L]
    // rewrites in your case to:
    http://localhost/code/index.php/home
    // which is what you wanted, aye?
    

提交回复
热议问题