search
HomePHP FrameworkThinkPHPHow to solve the problem that thinkphp cannot access the added path

1. Cause of the problem

When we add a path to the page, for example:

<link rel="stylesheet" type="text/css" href="__PUBLIC__/css/style.css">

If we find that the style is not loaded in the page table, it may be that the path is set incorrectly or is inaccessible. This may be caused by the "__PUBLIC__" alias not being set correctly in the ThinkPHP framework.

The path alias "__PUBLIC__" refers to the application's public folder path, which is located in the root directory of the application. If this path alias is not set correctly, the style sheet may not be accessible. Let's explore how to correctly set the alias for the "__PUBLIC__" path.

2. Solution

When setting the path alias "__PUBLIC__", you need to consider three aspects: the location of the application on the server and the configuration of the URL address. , Configuration of application file path.

  1. The location of the application on the server

The root directory of the application should be located in the document root directory of the web server to ensure that all files can be accessed.

  1. Configuration of URL address

Through the URL address, you can access various parts of the application. Therefore, the URL address needs to be configured correctly to ensure correct access of the path alias. The application's config.php file is the primary location for URL configuration in the ThinkPHP framework. You can configure the URL in config.php:

&#39;URL_MODEL&#39; => 2,
&#39;URL_HTML_SUFFIX&#39; => &#39;.html&#39;,
&#39;URL_CASE_INSENSITIVE&#39; => true,
&#39;URL_PATHINFO_FETCH&#39; => &#39;ORIG_PATH_INFO,REDIRECT_PATH_INFO,REDIRECT_URL&#39;
&#39;URL_ROUTER_ON&#39; => true,

For the meaning of each configuration item, you can check the official documentation of the ThinkPHP framework.

  1. Configuration of application file paths

The path aliases of each file in the application need to be configured correctly. For example, the path alias "__PUBLIC__" generally points to the "/public" folder, while the path alias "__ROOT__" points to the root directory of the application. If these path aliases are not configured correctly, the file will become inaccessible.

The above is the detailed content of How to solve the problem that thinkphp cannot access the added path. For more information, please follow other related articles on the PHP Chinese website!

Statement
This article is reproduced at:亿速云. If there is any infringement, please contact admin@php.cn delete

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

Video Face Swap

Video Face Swap

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

Hot Article

Hot Tools

MinGW - Minimalist GNU for Windows

MinGW - Minimalist GNU for Windows

This project is in the process of being migrated to osdn.net/projects/mingw, you can continue to follow us there. MinGW: A native Windows port of the GNU Compiler Collection (GCC), freely distributable import libraries and header files for building native Windows applications; includes extensions to the MSVC runtime to support C99 functionality. All MinGW software can run on 64-bit Windows platforms.

Dreamweaver Mac version

Dreamweaver Mac version

Visual web development tools

MantisBT

MantisBT

Mantis is an easy-to-deploy web-based defect tracking tool designed to aid in product defect tracking. It requires PHP, MySQL and a web server. Check out our demo and hosting services.

WebStorm Mac version

WebStorm Mac version

Useful JavaScript development tools

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment