How does CWP customize the subdomain folder directory path?Edit the vhosts file

due toWordfence pluginOther domain name paths cannot be scanned safely, so in order to facilitate the security scanning of the Wordfence plugin, it is necessary toWordPressThe image subdomain path is bound to the same domain name folder of the WordPress website.

VestaCPAnd its branch HestiaCP, you can customize the directory path of the domain name folder.

but,CWP Control PanelThe subdomain name folder path cannot be customized to bind to the path within the same domain name folder.

such as,Chen WeiliangThe blog has been bound to the subdomain folder path ▼

/home/用户名/public_html/chenweiliang.com

When adding a subdomain name, it is not effective to bind to the path within the same domain name folder ▼

/home/用户名/public_html/chenweiliang.com/wp-content/img.chenweiliang.com
  • Such a subdomain name folder path cannot be added...
  • Here is the solution.

CWP custom subdomain name folder directory path process

  1. First add the folder path of the subdomain name (set separately from other domain name folders):
    /home/用户名/public_html/img.chenweiliang.com
  2. Then, manually edit the vhosts file and replace the directory path of this domain name folder:
    /home/用户名/public_html/img.chenweiliang.com
  3. Replace with the following custom domain name folder directory path:
    /home/用户名/public_html/chenweiliang.com/wp-content/img.chenweiliang.com

How to edit the vhosts configuration file in CWP7 and replace the directory path of the domain name folder?

Step 1:Generate custom folder directory ▼

mkdir /home/用户名/public_html/chenweiliang.com/wp-content/img.chenweiliang.com

Step 2:Copy the image file to the directory location of the custom folder you just generated ▼

cp -rpf -f /home/用户名/public_html/img.chenweiliang.com/* /home/用户名/public_html/chenweiliang.com/wp-content/img.chenweiliang.com

Step 3:Enter the WebServers Configuration Editor, you need to edit the Nginx domain name vhosts configuration file separately.

Click "Edit" Nginx's domain name vhosts configuration file▼

  • WebServers Configuration Editor → WebServer Settings → /etc/nginx/conf.d/vhosts/ → Edit

How does CWP customize the subdomain folder directory path?Edit the vhosts file

  • /etc/nginx/conf.d/vhosts/img.chenweiliang.com.conf
  • /etc/nginx/conf.d/vhosts/img.chenweiliang.com.ssl.conf

Step 4: Replace this domain name folder directory path ▼

/home/用户名/public_html/img.chenweiliang.com

Replace with the following custom domain name folder directory path ▼

/home/用户名/public_html/chenweiliang.com/wp-content/img.chenweiliang.com

Step 5:Restart nginx service ▼

systemctl restart nginx

Step 6:Enter the WebServers Configuration Editor, you need to edit the Apache domain name vhosts configuration file separately.

Click "Edit" Apache's domain name vhosts configuration file▼

  • WebServers Configuration Editor → WebServer Settings → /usr/local/apache/conf.d/vhosts/ → Edit

Enter the WebServers Configuration Editor, edit the Apache domain name vhosts configuration file No. 2

  • /usr/local/apache/conf.d/vhosts/img.chenweiliang.com.conf
  • /usr/local/apache/conf.d/vhosts/img.chenweiliang.com.ssl.conf
  • WebServers Configuration Editor → WebServer Settings → /etc/nginx/conf.d/vhosts/ → Edit

Step 7: Replace this domain name folder directory path ▼

/home/用户名/public_html/img.chenweiliang.com

Replace with the following custom domain name folder directory path ▼

/home/用户名/public_html/chenweiliang.com/wp-content/img.chenweiliang.com

Step 8:Restart httpd service▼

systemctl restart httpd

Step 9:.htaccess file to add redirect exclude folder directory rule 

If there isWill automatically jump to the second-level domain name without the www top-level domain name, you need to add a redirection exclusion folder directory rule in the .htaccess file ▼

RewriteCond %{REQUEST_URI} !^/img.chenweiliang.com/.*$ [NC]

Put this code before the first rule to achieve the specified directory exclusion function ▼

RewriteEngine On
RewriteCond %{REQUEST_URI} !^/img.chenweiliang.com/.*$ [NC]
RewriteCond %{HTTP_HOST} !^www\. [NC]
RewriteRule ^(.*)$ http://www.%{HTTP_HOST}/$1 [R=301,L]

Step 10:Refresh the website to see if the changes take effect?

  • Close the subdomain CDN and refresh the subdomain website.

Step 11:Backup configuration files to local computer and Google Drive

  • If in WebServers Setting → Select WebServer, after saving and rebuilding the configuration, the above manually edited file contents will be invalid.
  • It needs to be edited manually again, which is very troublesome, so after manual editing, the files must be backed up to quickly restore the backed up configuration files.

The following is the command to quickly restore the backup vhost configuration file▼

cp -rpf -f /newbackup/backup-vhost-file/nginx-vhosts-file_modified/* /etc/nginx/conf.d/vhosts/

cp -rpf -f /newbackup/backup-vhost-file/apache-vhosts-file_modified/* /usr/local/apache/conf.d/vhosts/

After restoring the backup vhosts configuration file, be sure to restart nginx and httpd to take effect ▼

systemctl restart nginx
systemctl restart httpd
  • This is for record purpose and information only.

Step 12:使用Better Search Replace pluginmake path substitution

this path ▼

home/用户名/public_html/img.chenweiliang.com

replace with ▼

/home/用户名/public_html/chenweiliang.com/wp-content/img.chenweiliang.com

Step 13:Delete image subdomain ▼

rm -rf /home/用户名/public_html/img.chenweiliang.com

Step 14:After confirmation, restore the subdomain CDN

Hope Chen Weiliang Blog ( https://www.chenweiliang.com/ ) shared "How does CWP customize the subdomain folder directory path?Edit the vhosts file" to help you.

Welcome to share the link of this article:https://www.chenweiliang.com/cwl-28218.html

Welcome to the Telegram channel of Chen Weiliang's blog to get the latest updates!

🔔 Be the first to get the valuable "ChatGPT Content Marketing AI Tool Usage Guide" in the channel top directory! 🌟
📚 This guide contains huge value, 🌟This is a rare opportunity, don’t miss it! ⏰⌛💨
Share and like if you like!
Your sharing and likes are our continuous motivation!

 

Comment

Your email address will not be published. Required fields * Callout

scroll to top