admin管理员组

文章数量:1426058

I recently took over a WordPress site with the following directory structure inside of /public_html:

wp_config.php
/wp-admin
/wp-content
/wp-includes
...
...
...
/development 

The root (production) site is pointed to /public_html. Inside of /public_html, I have a sub-folder called /development. This subfolder has its own separate installation of Wordpress with a directory tree that looks like:

wp_config.php
/wp-admin
/wp-content
/wp-includes
...
...
...

You can access this WordPress instance via www.mywebsite/development. I am at a point where I would like to promote the development build to production.

What's the "WordPress" way of doing this? This is hosted on a machine that can be accessed via cPanel. I've noticed that while you can add "Addon Domains" and "Subdomains" via cPanel, you can't change the root public directory through cPanel. I would like to avoid SSHing into the machine and manually editing the httpd.conf file since that can cause conflicts with cPanel.

Ideally, I would like to avoid moving files all together and just point Apache's root directory to /public_html/development.

I recently took over a WordPress site with the following directory structure inside of /public_html:

wp_config.php
/wp-admin
/wp-content
/wp-includes
...
...
...
/development 

The root (production) site is pointed to /public_html. Inside of /public_html, I have a sub-folder called /development. This subfolder has its own separate installation of Wordpress with a directory tree that looks like:

wp_config.php
/wp-admin
/wp-content
/wp-includes
...
...
...

You can access this WordPress instance via www.mywebsite/development. I am at a point where I would like to promote the development build to production.

What's the "WordPress" way of doing this? This is hosted on a machine that can be accessed via cPanel. I've noticed that while you can add "Addon Domains" and "Subdomains" via cPanel, you can't change the root public directory through cPanel. I would like to avoid SSHing into the machine and manually editing the httpd.conf file since that can cause conflicts with cPanel.

Ideally, I would like to avoid moving files all together and just point Apache's root directory to /public_html/development.

Share Improve this question asked May 11, 2019 at 6:55 Lloyd BanksLloyd Banks 1213 bronze badges
Add a comment  | 

2 Answers 2

Reset to default 0

...just point Apache's root directory to /public_html/development

If you do this, I would seriously consider renaming "development" to "live" or something more meaningful, otherwise it's going to get confusing going forward.

Then you can create an .htaccess file in the document root with just the following mod_rewrite directive to rewrite everything to the /live subdirectory (rename the old .htaccess file .htaccess-old or something).

RewriteEngine On

RewriteRule (.*) /live/$1 [L]

This avoids a rewrite loop because of the .htaccess file in the /live subdirectory that contains the WordPress front-controller (of the development/live site).

You will need to make sure the URL structure does not contain the /development path segment.

This is as close to changing the document root you can get, without actually changing the document root.

I ended up taking the .htaccess and index.php files from /public_html/development and using them to replace the same files in /public_html.

Once you replace the two files, open up index.php (inside of /public_html) and update

require( dirname( __FILE__ ) . '/wp-blog-header.php' );

to

require( dirname( __FILE__ ) . '/development/wp-blog-header.php' );

with development being the name of the subdirectory you got your index.php and .htaccess files from.

After you replace the above two files, go to your WP Admin console associated with the build you would like to promote to production and then click on "Settings" -> "General". Find the Site Address (URL) input and update the value from https://www.mywebsite/development to https://www.mywebsite.

本文标签: htaccessWordPressPromoting A Dev Build In A Subdirectory To ProductionRoot Directory