codeigniter .htaccess work but cant find controlle

2019-09-10 02:38发布

问题:

i am using CI version 3.1.0

and inside my httacces file like this

RewriteEngine on
RewriteCond $1 !^(index\.php|public|\.txt)
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php?$1

and i have change my config file to $config['index_page'] = ''

i'ts work but CI seem cant find controller that request fromm url. example localhost/site/index.php/welcome its work as expected, but when request it with localhost/site/welcome i got 404 page not found.

回答1:

Could you try replacing the last line with

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

It depends a bit on the hosting, too I've noticed so this might not work. Is mod_rewrite or equivalent enabled?

If your application is running inside the directory /site/, what did you put in $config['base_url']?



回答2:

I'm using this:

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


回答3:

If you already follow this: tutorial, you need to set the AllowOverride directive to all in the path where your app is located. It is necessary because you are using an , .htaccess file. More.

When this directive is set to None and AllowOverrideList is set to None, .htaccess files are completely ignored. In this case, the server will not even attempt to read .htaccess files in the filesystem.

Remember:

You should avoid using .htaccess files completely if you have access to httpd main server config file. Using .htaccess files slows down your Apache http server. Any directive that you can include in a .htaccess file is better set in a Directory block, as it will have the same effect with better performance.

It is an developer recommendation: Here is.