Home > PHP Framework > ThinkPHP > How to solve the problem that thinkphp cannot access the added path

How to solve the problem that thinkphp cannot access the added path

王林
Release: 2023-05-27 16:37:45
forward
1365 people have browsed it

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">
Copy after login

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,
Copy after login

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!

Related labels:
source:yisu.com
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template