How to remove index.php with Codeigniter in Godadd

2019-09-01 05:51发布

问题:

i built a website with codeigniter and when i uploaded it it give me that error The requested document was not found on this server. i know that the problem is with my .htaccess code. so anyone can help me?

RewriteEngine on
RewriteCond $1 !^(index\.php|css|js|robots\.txt|images|itempics)
RewriteRule ^(.*)$ /index.php/$1 [L]

回答1:

Try this (anything listed in with the js|css etc will not use the rewrite

    Options +FollowSymlinks
    RewriteEngine on

    # On Rackspace and getting 404's? Uncoment this by removing the # :
    # RewriteBase /

    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_FILENAME} !-d

    <IfModule mod_rewrite.c>
       RewriteRule ^(.+)\.(\d+)\.(js|css|docs|img|invoices|support|demos|blog|devx)$ $1.$3 [L]
    </IfModule>

    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteRule ^(.*)$ index.php?/$1 [L]


回答2:

On one shared hosting I have this set:

RewriteEngine on
RewriteBase /
Options -Indexes
RewriteCond $1 !^(index\.php|robots\.txt|assets)
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php/\?$1 [L]

Also,

/*
|--------------------------------------------------------------------------
| Base Site URL
|--------------------------------------------------------------------------
|
| URL to your CodeIgniter root. Typically this will be your base URL,
| WITH a trailing slash:
|
|   http://example.com/
|
| If this is not set then CodeIgniter will guess the protocol, domain and
| path to your installation.
|
*/
$config['base_url'] = 'http://example.tld/';

/*
|--------------------------------------------------------------------------
| Index File
|--------------------------------------------------------------------------
|
| Typically this will be your index.php file, unless you've renamed it to
| something else. If you are using mod_rewrite to remove the page set this
| variable so that it is blank.
|
*/
$config['index_page'] = '';