你可以这样做,在config/config.php
:
$config['base_url'] = 'http://'.$_SERVER['HTTP_HOST']; //you can also leave blank this CI tend to find this by himself
$config['index_page'] = '';
并尝试以下.htaccess
. 我在很多网站上都使用它,它让我满意。
RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ /index.php/$1 [L]
如果它还不起作用,请使用 aphpinfo();
并检查 mod_rewrite 是否为enabled
. 如果未启用,您可以按照 Stack Overflow 问题How do you enable mod_rewrite?中的说明进行操作。启用它。
如果它还没有工作并且 mod_rewrite 还enabled
没有,你可以尝试将它们切换到config/config.php
:
$config['uri_protocol'] = 'AUTO'; //If not working, try one of these:
'PATH_INFO' Uses the PATH_INFO
| 'QUERY_STRING' Uses the QUERY_STRING
| 'REQUEST_URI' Uses the REQUEST_URI
| 'ORIG_PATH_INFO' Uses the ORIG_PATH_INFO