admin管理员组

文章数量:1410689

I currently have a website at site and have WordPress installed in me website's root folder. My website includes pages like:

  • site
  • site/page
  • site/2015/10/01/post....
  • site/login
  • site/wp-content/uploads/...

I would like to move all WordPress files into one subdirectory for sanity and NOT CHANGE ANY publicly facing URLs. Other posts here and and the official support thread talk about "Giving WordPress its own directory" but require changing URLs:

  • (site will load the homepage, but all other publicly facing URLs change)
  • Move wordpress to folder without changing urls (similar question but talks about install multiple blogs)

Please advise if this is possible.

I currently have a website at site and have WordPress installed in me website's root folder. My website includes pages like:

  • site
  • site/page
  • site/2015/10/01/post....
  • site/login
  • site/wp-content/uploads/...

I would like to move all WordPress files into one subdirectory for sanity and NOT CHANGE ANY publicly facing URLs. Other posts here and and the official support thread talk about "Giving WordPress its own directory" but require changing URLs:

  • https://codex.wordpress/Giving_WordPress_Its_Own_Directory (site will load the homepage, but all other publicly facing URLs change)
  • Move wordpress to folder without changing urls (similar question but talks about install multiple blogs)

Please advise if this is possible.

Share Improve this question asked Sep 1, 2015 at 18:09 William EntrikenWilliam Entriken 2552 gold badges3 silver badges9 bronze badges
Add a comment  | 

3 Answers 3

Reset to default 6

The procedure is thoroughly documented in Codex under Moving a Root install to its own directory.

You misunderstand the point about changing URLs in it, and yes the terminology sucks. The only URLs that will change are those that are based on the "WP address". That would be WordPress core, essentially the admin area.

All content URLs are based on "Site address", following this procedure, that will still be the root of your site.

Since you want to retain uploads in place, you can do that by keeping wp-content in the root (splitting it out of core folder) and adjusting configuration for that. See Moving wp-content folder.

Okay, here is how it is done:

  1. Move wp-*, index.php, .htaccess to your new wordpress folder
  2. Edit wordpress/.htaccess:

    • Find this line: RewriteRule . /index.php [L]
    • Make it: RewriteRule . /wordpress/index.php [L]
  3. Create a new file in /path/to/www called .htaccess then add this:

RewriteEngine on
RewriteRule ^$ https://www.example/ [L]

<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteRule ^/wordpress/index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ /wordpress/$1 [L]
</IfModule>

Method for moving Wordpress files to another folder (directory) without changing the Wordpress configuration, i.e., completely transparent to Wordpress:

  1. create a directory where the Wordpress installation will be moved into, e.g. "sitedir"
  2. move the WP installation, including .htaccess, into that newly created directory
  3. edit the .htaccess file in the www root directory (likely public_html) and insert the following stances:
    RewriteEngine On
    RewriteBase /

    # redirect to ./sitedir/
    RewriteCond %{http_host} ^example\$
    RewriteCond %{request_uri} !^/sitedir(/.*)$
    RewriteRule ^(.*)$ /sitedir/$1 [L,QSA]

    # extra, redirect www.example to example
    RewriteCond %{http_host} ^www\.example\ [NC]
    RewriteRule ^(.*) http://example/$1 [R=301,L]

Replace "example" with your domain and "sitedir" with the name of the folder that WP would be placed in.

本文标签: permalinksMove Wordpress to subdirectorykeep ALL URLs