0

I'm trying to optimize a site and the last thing I want to do is to serve static content with a subdomain that will be without cookies, and I have a problem with that.

I tried a couple of things to do and I will describe what I did and what problems I had.

I first added the DNS record to hosting for the subdomain, set as A record and the content is set to server IP. Then added a subdomain in the control panel of the domain provider, set to the Authoban option used to serve static content at high speed. Then added a subdomain via cPanel and set Document Root to "public_html/wp-content/uploads" and added the following code to the top of the wp-config.php file:

define("WP_CONTENT_URL", "http://static.mysite.com"); 

After this, it was not possible to load the site and loading of WP admin panel was very slow and also it was not possible to load images inside the admin panel media tab.

The other thing I did was change the subdomain setting, on hosting and control panel of the domain provider, to the CNAME DNS record that points to main domain.

And after this change the loading of the site was very slow and only html was loaded, and there were errors about loading images and scripts from a static subdomain, in fact, it was not possible to access them.

Another important thing is that the site uses CloudFlare, but I do not currently have access data, I should soon have to get them.

So does anyone know where I'm wrong and how to do this right?

2 Answers 2

1

Good Day

A point not mentioned in this topic is that WordPress can only read and write its media files in the path where it is installed by default. As a result, if you try to use a path outside of its installation—such as on another server or a separate subdomain—you will encounter a 404 error, even after setting and changing the storage path in the subdomain's root.

The only solution to this issue is to configure the subdomain's storage path in DirectAdmin or cPanel as follows to prevent errors.

Enter the following address in your browser: https://yourdomain.ir/wp-admin/options.php

Then, navigate to the settings related to file paths and link addressing:

Set "upload_path" like this: static/media (Note: The media name should not end with a slash, as it will cause a folder access level error.)

Set "upload_url_path" like this: https://static.yourdomain.com

Attention: If your site's linking structure uses SSL or starts with "www," ensure the linking is consistent with your main site's addressing to avoid issues with displaying two different sites.

Subdomain management settings in the hosting control panel: If the subdomain Docroot is set like this: /domains/static.yourdomain.ir/public_html

Change it to: /domains/yourdomain.ir/public_html/static

This change ensures that files are written and read in the root of the main domain, eliminating the 404 error. Additionally, the files will be addressed through the subdomain.

According to this tutorial, the WordPress system can only read files in the main root of the host (the path where WordPress is installed). When a subdomain is created with a separate root (like another domain), it behaves as if it cannot read or execute files in that separate root. There is no difference in running files on a subdomain in "separate root" or "inside the main root" mode. In the past, subdomains were only created in "inside the main root" mode. In newer versions of DirectAdmin and cPanel, options like "separate root" have been added, allowing users to manage subdomain files independently if needed.

Thank you

0

The Solution is in the Document root of your subdomain.

You must set it to "public_html/wp-content" because it also loads your themes' files which are outside the uploads directory

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.