In actual development, sometimes we need to hide the domain name after going online to avoid being attacked. Developers using the ThinkPHP framework can use some methods to achieve this goal.
- Using routing
Idea: Hide the actual URL address by defining a routing rule.
The steps are as follows:
(1) Modify the project configuration file (config.php) and define a routing rule:
'路由規(guī)則'?=>?'目標(biāo)地址'
For example:
'test'?=>?'index/index/hello'
It means that when accessing "http://domain name/test", jump to the "hello method of index controller index operation".
(2) Enter "http://domain name/test" in the browser address bar, and you will see that the actual URL address has been hidden.
- Use pseudo-static
Idea: Use pseudo-static technology to convert the URL address into a search engine-friendly form, and also have the effect of hiding the URL address.
The steps are as follows:
(1) Configure pseudo-static on the Apache server and place the ".htaccess" file in the root directory of the website.
(2) Add the following code in the "index.php" file of the project:
if?(!is_file('./html'?.?$_SERVER['REQUEST_URI']?.?'.html'))?{ ????//?生成html文件 ????ob_start(); ????//?渲染頁面 ????$content?=?ob_get_clean(); ????//?保存為靜態(tài)文件 ????file_put_contents('./html'?.?$_SERVER['REQUEST_URI']?.?'.html',?$content); } //?輸出靜態(tài)文件 echo?file_get_contents('./html'?.?$_SERVER['REQUEST_URI']?.?'.html');
means: if the corresponding HTML file exists, output the file; otherwise, in "html "Generate a corresponding static HTML file in the directory and output the content.
(3) Enter the URL address corresponding to the page in the browser address bar, and you will see that the actual URL address has been hidden.
- Use reverse proxy
Idea: Use reverse proxy technology to use an address as a representative and forward all requests to this address. At the same time, on the representative address Configure reverse proxy rules to forward requests to the real address.
The steps are as follows:
(1) Configure reverse proxy rules on the Nginx server and add the following code to the "/etc/nginx/nginx.conf" file:
server?{ ????listen?80; ????server_name?域名; ????location?/?{ ????????proxy_pass?http://真實的地址; ????????proxy_set_header?Host?$host; ????} }
It means: forward all requests to the real address, and set the "Host" header parameter in the target address to the domain name of the current host.
(2) Enter the representative address in the browser address bar to access the real address, and the actual URL address has been successfully hidden.
Summary
Based on the above three options, we can choose which method is more suitable for our project based on actual needs. Through the above methods, we can not only ensure the security of website operation, but also provide users with a better access experience.
The above is the detailed content of How to hide domain name after thinkPHP goes online. For more information, please follow other related articles on the PHP Chinese website!

Hot AI Tools

Undress AI Tool
Undress images for free

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Clothoff.io
AI clothes remover

Video Face Swap
Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Article

Hot Tools

Notepad++7.3.1
Easy-to-use and free code editor

SublimeText3 Chinese version
Chinese version, very easy to use

Zend Studio 13.0.1
Powerful PHP integrated development environment

Dreamweaver CS6
Visual web development tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)
