Hideindex.php
is a common operation in the process of using the TP3 framework, which can improve the beauty and security of the website. This article will introduce how to configure the TP3 framework to hide index.php
and the precautions, and provide specific code examples.
Modify the entry file
First, you need to modify the entry file index.php
. Change the code in the original index.php
file to the following code:
define('APP_PATH', './Application/'); define('APP_DEBUG', true); require './ThinkPHP/ThinkPHP.php';
Configure routing
In Conf /config.php
file for routing configuration, add the following code:
'URL_MODEL' => 2, 'URL_ROUTER_ON' => true, 'URL_ROUTE_RULES' => array( '自定义路由规则' => '具体控制器/方法', )
Configure pseudo-static
Create in the root directory of the website.htaccess
file and add the following content:
RewriteEngine On RewriteCond %{REQUEST_FILENAME} !-d RewriteCond %{REQUEST_FILENAME} !-f RewriteRule ^(.*)$ index.php/ [QSA,PT,L]
Conf/config.php
file App_DEBUG
configuration item and modify its value to false
to turn off debugging mode. index.php
file and Configuration file to prevent the website from being inaccessible due to operational errors. index.php
operation takes effect and that the website can be accessed normally. Suppose we have a controller IndexController
, which contains a method index
, which can be hidden by configuring routing rules index.php
and access the method. The specific sample code is as follows:
// 在Contrloller 文件中定义IndexController.php class IndexController extends Controller { public function index() { echo 'Hello, TP3!'; } } // 在配置路由时添加以下规则 'URL_ROUTE_RULES' => array( 'hello' => 'Index/index', )
Through the above operations, when accessing http://yourdomain.com/hello
, the actual access is ## in IndexController
#index method, the page will output
Hello, TP3!.
index.php in the TP3 framework and improve the beauty and security of the website. In actual operation, careful configuration and reasonable planning of routing rules are required to ensure the normal operation of the website. Hope this article is helpful to you.
The above is the detailed content of Configuration methods and precautions for hiding index.php in TP3. For more information, please follow other related articles on the PHP Chinese website!