thinkphp3 把入口文件放到自定义目录 防止 AppRuntime目录被用户通过浏览器访问到

mac2022-06-30  117

1. 新建目录www 把index.php文件放进去

修改www/index.php文件

<?php // 应用入口文件 //exit("内测结束"); // 检测PHP环境 if(version_compare(PHP_VERSION,'5.3.0','<')) die('require PHP > 5.3.0 !'); // 开启调试模式 建议开发阶段开启 部署阶段注释或者设为false define('APP_DEBUG', true); // 定义应用目录 define('APP_PATH', realpath('../App/').'/'); define('BIND_MODULE','Index'); define('THINK_PATH', realpath('../ThinkPHP').'/'); define('RUNTIME_PATH', realpath('../App/Runtime/').'/'); define('LIB_PATH', THINK_PATH.'/Library/'); define('COMMON_PATH', APP_PATH.'/Common/'); // 引入ThinkPHP入口文件 require realpath('../ThinkPHP/ThinkPHP.php');

realpath在windows下返回空字符串 '', ?

在linux下正常

 

2. 配置web服务器 把发布目录改到www下

下面是apache的示例

<VirtualHost *:8022> ServerAdmin mzh@localhost DocumentRoot "/Volumes/Applications/project/toUpgrade/www" ErrorLog "/Volumes/Applications/project/toUpgrade/App/Runtime/Logs/error.log" CustomLog "/Volumes/Applications/project/toUpgrade/App/Runtime/Logs/info.log" common <Directory "/Volumes/Applications/project/toUpgrade/www"> Options Indexes FollowSymLinks Includes ExecCGI AllowOverride All Require all granted </Directory> </VirtualHost>

3. 把模板文件和其他前端需要的图片,css,js文件放到www目录

其他的tp3漏洞:

https://blog.csdn.net/q1352483315/article/details/92164201

 

对于windows路径:

<?php // 应用入口文件 //exit("内测结束"); // 检测PHP环境 if(version_compare(PHP_VERSION,'5.3.0','<')) die('require PHP > 5.3.0 !'); // 开启调试模式 建议开发阶段开启 部署阶段注释或者设为false define('APP_DEBUG', true); //error_reporting(E_ALL); //ini_set('display_errors', 1); // 定义应用目录 define('APP_PATH', realpath('../App/').DIRECTORY_SEPARATOR); define('BIND_MODULE','Index'); define('THINK_PATH', realpath('../ThinkPHP').DIRECTORY_SEPARATOR); define('RUNTIME_PATH', realpath('../App/Runtime/').DIRECTORY_SEPARATOR); define('LIB_PATH', THINK_PATH.'/Library/'); define('COMMON_PATH', APP_PATH.'/Common/'); // 引入ThinkPHP入口文件 require realpath('../') . DIRECTORY_SEPARATOR.'ThinkPHP'.DIRECTORY_SEPARATOR.'ThinkPHP.php';

thinkphp3 url rewrite

 Apache 

httpd.conf配置文件中加载了mod_rewrite.so模块AllowOverride None 将None改为 All

把下面的内容保存为.htaccess文件放到应用入口文件的同级目录下

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

[ Nginx ]

在Nginx低版本中,是不支持PATHINFO的,但是可以通过在Nginx.conf中配置转发规则实现:

location / { // …..省略部分代码 if (!-e $request_filename) { rewrite ^(.*)$ /index.php?s=$1 last; break; } }

http://document.thinkphp.cn/manual_3_2.html#url_rewrite

最新回复(0)