How to allow wordpress to access by "relative path"

Source: Internet
Author: User

Wordpress does not support relative paths, which is not conducive to access by multiple domain names. How can I enable wordpress to operate in a relative path?

You can log on to the backend-setting-options and set the wordpress url, otherwise, the system will ask you to reinstall wordpress. After confirmation, the wordpress url column is empty, but in the database, the value of siteurl is "/".

The above method is no longer available in the new version of wordpress, so people want to directly modify the corresponding field in the database as "/". This seems to work in many occasions.

However, the absolute path must be used according to the wordpress logic. Many of its functions use the home and siteurl variables. Simply change their values to "/", which leads to a high possibility of problems. A better way is to follow the design logic of wordpress access by absolute path and try another method.

This method is actually very simple, that is, first determine the access domain name, and then assign this domain name to the home and siteurl two global variables. The specific method is very violent is also very simple, do not change the database, just need to add the following statement at the end of the wp-config.php:

<? Php

$ Home = 'HTTP: // '. $ _ SERVER ['HTTP _ host'];
$ Siteurl = 'HTTP: // '. $ _ SERVER ['HTTP _ host'];
Define ('wp _ home', $ HOME );
Define ('wp _ siteurl', $ SITEURL );

?>

After this modification, the setting-options page in the background can only be displayed, but the home and siteurl values cannot be modified because they have been defined as two constants ), they are completely displayed based on the access domain name.

This method not only enables wordpress to access the content of the entire site in a "relative path" mode, but also conforms to the design logic of wordpress's tangled absolute path. It should be the best solution. However, it should be noted that after this modification, the path of the media files such as the image inserted during editing is still an absolute path. After insertion, You need to manually change the Domain Name of the path to remove it.

This article is from the "structured thinking" blog, please be sure to keep this source http://yuanxi.blog.51cto.com/2149074/980913

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.