Remove “index.php” from URL - Codeigniter

前端 未结 12 1128
清酒与你
清酒与你 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:24

    I have the same problem, the things is.

    1. htacces should be in the root of Codeigniter
    2. Remove "Deny from all" in your htacces file.
    3. Add the code on the post above
    0 讨论(0)
  • 2020-12-03 16:28

    Try...

    RewriteEngine on
    RewriteBase /code/
    RewriteCond $1 !^(index\.php|images|robots\.txt)
    RewriteRule ^(.*)$ code/index.php/$1 [L]
    
    0 讨论(0)
  • 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?
    
    0 讨论(0)
  • 2020-12-03 16:29

    You should change

    RewriteRule ^(.*)$ /index.php/$1 [L]
    

    to

    RewriteRule ^(.*)$ /code/index.php/$1 [L]
    

    You also need to modify the $config['index_page'] variable like this:

    $config['index_page'] = '';
    

    Please refer to my post at http://www.boxoft.net/2011/07/removing-index-php-from-codeigniter-2-0-2-url/ if you like.

    0 讨论(0)
  • 2020-12-03 16:31

    Try this one

    DirectoryIndex index.php
    RewriteEngine on
    RewriteCond $1 !^(index\.php|(.*)\.swf|forums|images|css|downloads|js|robots\.txt|favicon\.ico)
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteRule ^(.*)$ ./index.php?$1 [L,QSA] 
    

    I tried 3 before I got one to work

    0 讨论(0)
  • 2020-12-03 16:31
    RewriteEngine on
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteRule ^(.*)$ index.php/$1 [L]
    

    Create an .htacess file on the root folder of your web directory in codeigniter using the above code. You will be able to remove index.php if an url link contains index.php so it will display page with no error. Or if url doesn't contains index.php it will display the page without index.php in url.

    0 讨论(0)
提交回复
热议问题