问题
I have successfully installed CI in the root directory many times, but now I have been forced to install CI in https://mydomain.com/mvc
There exists one controller "Login" with one action "index"
The .htaccess file looks like:
Options +FollowSymLinks
RewriteEngine on
RewriteBase /mvc
RewriteRule ^(.*)$ index.php?/$1 [L]
In config/config.php
$config['base_url'] = 'https://mydomain.com/mvc/';
$config['index_page'] = '';
My routes look like:
$route['default_controller'] = "login";
$route['login'] = "login/index";
$route['404_override'] = '';
mod_rewrite is enabled
https://mydomain.com/mvc gives a 404
https://mydomain.com/mvc/login gives a 404
What do I miss?
回答1:
What´s your hosting? if is hostgator you need add your user.
Try this
RewriteEngine On
RewriteBase /mvc
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ /mvc/index.php/$1 [L]
if your hosting is hostgator you need add you name user, for example
RewriteEngine On
RewriteBase /~<name_user>/%{HTTP_HOST} <or> <your folder>
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ /~<name_user>/%{HTTP_HOST} <or> <your folder>/index.php/$1 [L]
回答2:
Try this Set you default base url for subdirectory
$config['base_url'] = "http://www.example.com/subdir/"
Open config.php and do following replaces
$config['index_page'] = "index.php"
to
$config['index_page'] = ""
In some cases the default setting for uri_protocol does not work properly. So you have just replace it
$config['uri_protocol'] ="AUTO"
by
$config['uri_protocol'] = "REQUEST_URI"
.htaccess
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php/$1 [L]
This code run all sub directory. Hope this will help you!.
回答3:
try this
RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ /mvc/index.php?/$1 [L]
回答4:
I had the same issue and I could fix it by updating /etc/apache2/sites-enabled/000-default.conf
file
try this.
mvc/.htaccess
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php?/$1 [L]
</IfModule>
mvc/application/config/config.php
$config['base_url'] = 'https://yourdomain.com/mvc/';
/etc/apache2/sites-enabled/000-default.conf
<VirtualHost *:80>
....
<Directory /your/root/directory> # /var/www/html
Options Indexes FollowSymLinks MultiViews
AllowOverride All
Require all granted
</Directory>
</VirtualHost>
来源:https://stackoverflow.com/questions/21469367/codeigniter-2-1-4-installation-in-sub-directory