ThinkCMF入口文件移到根目录

理论上来讲,入口文件最好不要放到根目录。原因就不展开说了

 

之所以把入口文件index.php移动到根目录,是因为客户选的是景安的虚拟空间。

根目录没法自己设置,只能是xxx/web/ 

 

没办法,只能想办法移动了。根据ThinkPHP5.0官方文档,文件本身移动之后,还需要改根目录配置。

index.php line 16 

// 定义CMF根目录,可更改此目录
define('CMF_ROOT', __DIR__ . './');

 原以为改了这些就可以了,没想到根本没有这么简单。

 

改完之后,本地测试报模板路径错误。经过很长时间的调试,找到原因,需修改模板路径。(按道理来讲,模板路径应该不用更改的) 

修改app/config.php line 222

// +----------------------------------------------------------------------
// | CMF 设置
// +----------------------------------------------------------------------
'cmf_theme_path' => 'public/themes/',
'cmf_default_theme' => 'simpleboot3',
'cmf_admin_theme_path' => 'public/themes/',
'cmf_admin_default_theme' => 'admin_simpleboot3',

两处添加public 

修改之后,不报错了,html可以正常显示,但图片无法正常显示。

还需修改simplewind\cmf\lib\storage\Local.php line 50

return cmf_get_root() . '/public/upload/' . $file;

 

 至此,首页可以正常显示。

 

浏览其他页面,提示路径错误。

想到应当将.htaccess等文件一并移到根目录。移动之后,本地正常。

虚拟空间依旧提示路径错误。

虚拟空间是IIS+PHP

猜测原因可能是.htaccess文件没有起作用。

按照ThinkPHP5.0官方文档中URL重写的方法,修改服务器根目录的web.config文件

<system.webServer>

的下一行,插入以下内容:

<rewrite>
<rules>
<rule name="OrgPage" stopProcessing="true">
<match url="^(.*)$" />
<conditions logicalGrouping="MatchAll">
<add input="{HTTP_HOST}" pattern="^(.*)$" />
<add input="{REQUEST_FILENAME}" matchType="IsFile" negate="true" />
<add input="{REQUEST_FILENAME}" matchType="IsDirectory" negate="true" />
</conditions>
<action type="Rewrite" url="index.php/{R:1}" />
</rule>
</rules>
</rewrite>

再次测试,正常了。 

 

posted @ 2017-09-16 20:57  长空5  阅读(1526)  评论(0)    收藏  举报