简体   繁体   中英

Codeigniter default controller not working

I have almost finished a web application using Codeigniter. In development, the root directory is /readme/ and I use the following code in .htaccess to eliminate index.php in the URL:

RewriteEngine On
RewriteBase /readme
RewriteCond %{REQUEST_URI} ^system.*
RewriteRule ^(.*)$ /index.php/$1 [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php/$1 [L]

I also set Readme_home as the default controller, so the following URL will directly points to the default controller:

http://localhost/readme

For production, I use the exact same configuration as the one for development but the following URL does not work and produce ' Directory access is forbidden ' error:

http://www.mydomain/readme

Instead, I have to use

http://www.mydomain/readme/readme_home

for the default controller to appear. Is there any missing configuration? If anyone can point out any reference on the web about this problem, that would be good enough. Let me know if I have to add additional information. Thank you sir, and I really appreciate it.

Try:

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

Depending on your host, your uri_protocol might not be detected properly. In your config/config.php file, switch uri_protocol to any of the options listed. I've had the same issue when running my app on a VPS. Currently, PATH_INFO works.

/*
|--------------------------------------------------------------------------
| URI PROTOCOL
|--------------------------------------------------------------------------
|
| This item determines which server global should be used to retrieve the
| URI string.  The default setting of 'AUTO' works for most servers.
| If your links do not seem to work, try one of the other delicious flavors:
|
| 'AUTO'            Default - auto detects
| '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
|
*/
$config['uri_protocol'] = 'PATH_INFO';

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM