简体   繁体   中英

Run wordpress on a separate directory

I would like to run a wordpress site through a subdirectory but keep the actual domain.

Here is what I am trying to do.

Let's say, I have a site www.xyz.com

I have a wordpress instance installed on the root directory. However, i want to install a new wordpress instance in a subdirectory. I want to point the root worpdress instance to the subdirectory and keep the domain name without referencing to the subdirectory.

The subdirectory can be called let's say " test ". In the test directory, I will install a new wordpress instance.

Now, I want to point www.xyz.com to the "test" directory and still have the link as www.xyz.com. All the links should be www.xyz.com/post-name-sample and not www.xyz.com/test/post-name-sample.

Is there a mod-rewrite rule I need to setup within the .htaccess file?

Any help is appreciate. Thank you!

Try adding this to the .htaccess file

 .htaccess main domain to subfolder redirect
 # Copy and paste the following code into the .htaccess file
 # in the public_html folder of your hosting account
 # make the changes to the file according to the instructions.

 # Do not change this line.
 RewriteEngine on

 # Change yourdomain.co.uk to be your main domain.
 RewriteCond %{HTTP_HOST} ^(www.)?yourmaindomain.co.uk$

 # Change ‘subfolder’ to be the folder you will use for your main domain.
 RewriteCond %{REQUEST_URI} !^/subfolder/

 # Don’t change this line.
 RewriteCond %{REQUEST_FILENAME} !-f
 RewriteCond %{REQUEST_FILENAME} !-d

 # Change ‘subfolder’ to be the folder you will use for your main domain.
 RewriteRule ^(.*)$ /subfolder/$1

 # Change yourdomain.co.uk to be your main domain again.
 # Change ‘subfolder’ to be the folder you will use for your main domain
 # followed by / then the main file for your site, index.php, index.html, etc.

 RewriteCond %{HTTP_HOST} ^(www.)?yourmaindomain.co.uk$
 RewriteRule ^(/)?$ subfolder/index.php [L]

It is possible to do with on wordpress: here is how to do it if you have it installed in a subdirectory already.

  1. Go to the General panel.
  2. In the box for Site address (URL): change the address to the root directory's URL. Example: http://example.com
  3. Click Save Changes. (Do not worry about the error message and do not try to see your blog at this point! You will probably get a message about file not found.)
  4. Copy (NOT MOVE!) the index.php and .htaccess files from the WordPress (wordpress in our example) directory into the root directory of your site—the latter is probably named something like www or public_html. The .htaccess file is invisible, so you may have to set your FTP client to show hidden files. If you are not using pretty permalinks, then you may not have a .htaccess file. If you are running WordPress on a Windows (IIS) server and are using pretty permalinks, you'll have a web.config rather than a .htaccess file in your WordPress directory.
  5. Edit your root directory's index.php.
    1. Open your root directory's index.php file in a text editor
    2. Change the line that says: require( dirname( __FILE__ ) . '/wp-blog-header.php' ); to the following, using your directory name for the WordPress core files: require( dirname( __FILE__ ) . '/wordpress/wp-blog-header.php' );
    3. Save the file.
  6. Login to your site (if you aren't still already). The URL should still be http://example.com/wordpress/wp-admin/
  7. If you have set up Permalinks, go to the Permalinks panel and update your Permalink structure. WordPress will automatically update your .htaccess file if it has the appropriate file permissions. If WordPress can't write to your .htaccess file, it will display the new rewrite rules to you, which you should manually copy into your .htaccess file (in the same directory as the main index.php file.)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM