CodeIgniter won't run in a subdirectory

我只是一个虾纸丫 提交于 2019-12-13 07:39:14

问题


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:


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.



来源:https://stackoverflow.com/questions/11380313/codeigniter-wont-run-in-a-subdirectory

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!