CodeIgniter won't run in a subdirectory

2019-09-09 09:42发布

I have a CodeIgniter install running in our root web directory that I copied into a subdirectory called /dev... I edited the config/config.php file to reflect the change so it is now like this:

$config['base_url']  = 'http://mysite.com/dev';
$config['sbase_url']     = 'https://mysite.com/dev';
$config['default_email'] = 'noreply@mysite.com';
$config['site_url']  = 'http://mysite.com/dev';

This is my .htaccess file:

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

When I hover over any links on the site they are correct, for example the contact us page link reads www.mysite.com/dev/contact but when I click any of the links I get a 404 error...

Is there something common I am missing?

1条回答
三岁会撩人
2楼-- · 2019-09-09 09:56

Enable FollowSymlinks & add a ./ in front of index.php in your RewriteRule:

<IfModule mod_rewrite.c>
  Options +FollowSymlinks
  RewriteEngine On

  # block hidden directories
  RewriteRule "(^|/)\." - [F]

  RewriteCond %{REQUEST_FILENAME} !-f
  RewriteCond %{REQUEST_FILENAME} !-d
  RewriteRule ^(.*)$ ./index.php/$1 [L,QSA]
</IfModule>

Also, I would leave blank $config['base_url'] = ''; & use the base_url() url helper when constructing links instead, which makes moving environments easier (e.g. subdir'd dev & root-level production).

... and of course, insure that ModRewrite is enabled in your Apache config.

查看更多
登录 后发表回答