dede cfg_basehost是什么?如何配置使用?

99ANYc3cd6
预计阅读时长 20 分钟
位置: 首页 DEDE建站 正文

Of course. Let's break down what cfg_basehost is in DedeCMS, why it's important, and how to configure it correctly.

dede cfg basehost
(图片来源网络,侵删)

What is cfg_basehost?

In simple terms, cfg_basehost is a global configuration variable in DedeCMS that stores your website's base URL.

It's defined in the configuration file include/common.inc.php. When you install DedeCMS, it sets this variable to the domain you provided during the installation process.

Example: If your website is https://www.example.com, the cfg_basehost variable will be set to: 'https://www.example.com'

Why is cfg_basehost So Important?

This variable is the cornerstone of how DedeCMS generates absolute URLs for your website. Instead of hard-coding URLs throughout the system, DedeCMS uses this central variable. This provides several key benefits:

dede cfg basehost
(图片来源网络,侵删)
  1. Portability: If you ever need to move your website from a development server (e.g., http://localhost/my_site) to a live server (e.g., https://www.example.com), you only need to change this single value in the configuration file. You don't have to hunt through hundreds of files to update URLs.

  2. Consistency: It ensures that every link generated by the system (links to articles, images, CSS, JavaScript, etc.) uses the correct base domain. This prevents broken links and mixed content issues (e.g., http on an https page).

  3. Functionality: Many core DedeCMS functions rely on cfg_basehost to build their output. For example:

    • {dede:global.cfg_basehost/}: This is a standard DedeCMS template tag you can use directly in your HTML templates to output the base URL.
    • Image Paths: When DedeCMS generates the path for an image uploaded to the media library, it prepends cfg_basehost to make it a full, accessible URL.
    • URL Rewriting: It works in conjunction with the URL rewriting rules to ensure that all links, including those in the <head> section (for canonical tags, Open Graph tags, etc.), are correct.

Where is cfg_basehost Defined and Used?

Definition (Where to set it)

The variable is defined in the file: /include/common.inc.php

dede cfg basehost
(图片来源网络,侵删)

You will find a line that looks like this:

$cfg_basehost = 'https://www.your-domain.com'; // <--- YOU WILL EDIT THIS LINE

How to Edit It:

  1. Access your website's files via FTP or a File Manager in your hosting control panel.
  2. Navigate to the /include/ directory.
  3. Edit the file common.inc.php.
  4. Find the $cfg_basehost line and change the URL to your correct domain.
  5. Crucially, save the file and upload it back to your server.

Important Note: If your website uses HTTPS (SSL certificate), you must use https:// in the cfg_basehost value. Using http:// on an HTTPS site will cause browser security warnings (mixed content) and break functionality.

Usage (Where it's used)

  • In DedeCMS Templates: You can use the template tag directly in your .htm template files.

    <!-- Link to your homepage -->
    <a href="{dede:global.cfg_basehost/}/">Go to Homepage</a>
    <!-- Use in Open Graph tags for social media sharing -->
    <meta property="og:url" content="{dede:global.cfg_basehost/}{dede:field name='arcurl'/}" />
  • In PHP Code: It's used extensively within the DedeCMS PHP codebase to generate full URLs. For example, in the arc.archives.class.php file (which handles article displays), it's used to build the canonical URL for SEO.

Troubleshooting Common Problems with cfg_basehost

If cfg_basehost is not set correctly, you will likely experience one or more of the following issues:

Problem 1: Images Not Showing

Symptom: Images in your articles or on your site appear as broken links (a generic image icon). Cause: The cfg_basehost is either incorrect (e.g., pointing to localhost instead of your live domain) or missing the https:// prefix. Solution:

  1. Check if your site is running on http or https.
  2. Edit /include/common.inc.php and ensure $cfg_basehost points to the fully qualified domain name with the correct protocol.

Problem 2: Mixed Content Security Warnings in Browser

Symptom: Your browser's address bar shows a "Not Secure" warning, or the console logs errors about "mixed active content." Cause: Your site is loaded over https, but cfg_basehost is set to http://www.example.com. This causes the browser to block insecure resources (images, scripts) from being loaded. Solution:

  1. Edit /include/common.inc.php.
  2. Change $cfg_basehost from http://... to https://....

Problem 3: Links are Incorrect After Moving a Site

Symptom: You moved your DedeCMS site from one domain to another, but all the links still point to the old domain. Cause: You updated the database (for posts, etc.) but forgot to update the core configuration variable. Solution:

  1. Edit /include/common.inc.php.
  2. Change the value of $cfg_basehost to your new domain name.
  3. Save the file. Clear your browser cache and the server's cache (if you have a caching plugin like PHP Opcode Cache enabled).

Summary

Feature Description
What it is A global variable in DedeCMS that stores your website's base URL (e.g., https://www.example.com).
Where to set it In the file /include/common.inc.php.
Why it matters It ensures all URLs generated by the system are correct, portable, and consistent.
Common Fix If images are broken or you get security warnings, the most likely cause is an incorrect protocol (http vs https) or an outdated domain name in this variable.
-- 展开阅读全文 --
头像
dede loop标签如何正确使用?
« 上一篇 昨天
C语言popen如何获取stdout输出?
下一篇 » 今天

相关文章

取消
微信二维码
支付宝二维码

目录[+]