{"id":24827,"date":"2016-10-12T15:18:09","date_gmt":"2016-10-12T13:18:09","guid":{"rendered":"http:\/\/www.dragosoft.info\/?p=24827"},"modified":"2022-02-14T09:17:31","modified_gmt":"2022-02-14T09:17:31","slug":"moving-wordpress-from-root-directory-to-sobs","status":"publish","type":"post","link":"https:\/\/dragosoft.info\/en\/moving-wordpress-from-root-directory-to-sobs\/","title":{"rendered":"Moving WordPress from Root to own directory and back"},"content":{"rendered":"<p>Most people want their WordPress site to load from the main web address (e.g. http:\/\/example.com ), but at the same time they don't want the whole mess of WordPress files in the main \/root\/ directory. WordPress allows you to install it in a subdirectory, but have the site load from your main web address. When you initially install WordPress you have the option to set it to install in the main \/server directory of the hosting or in its own subdirectory, but you can change this later if you choose. This may be dictated by a variety of considerations, for example you already have a website installed in the main directory but wish to migrate to WordPress whilst wanting to maintain your Google search rank. In this case, it is a good idea to install WordPress in a subdirectory, with the address that will load for example being http:\/\/example.com\/\u0438\u043c\u0435-\u043d\u0430-\u043f\u043e\u0434\u0434\u0438\u0440\u0435\u043a\u0442\u043e\u0440\u0438\u044f\/ and later redirect it to the main web address http:\/\/example.com\/, while also redirecting the old site to the new one. Or you may just have several sites uploaded to the hosting account\/server and want each to be in a separate folder for clarity. But let's not get carried away. How can we move\/redirect a WordPress site from the main directory to a subdirectory and vice versa? That's what we'll cover in the next few lines.<\/p>\n<ol>\n<li>\n<h2><strong>Moving from Root to your own directory<\/strong><\/h2>\n<\/li>\n<\/ol>\n<p>First we create the new directory where we will move the main WordPress files (I will use \/WordPress\/ in our examples). Then we go into the site's admin panel Settings &gt; General in the <strong>WordPress URL:<\/strong> change the address of the place where we have moved the main WordPress files. Example: http:\/\/example.com\/wordpress<\/p>\n<p>In the field for <strong>URL:<\/strong> leave the same URL or if different - the URL of the main directory for example: http:\/\/example.com<\/p>\n<p><img decoding=\"async\" class=\"alignnone wp-image-37202 size-full\" src=\"https:\/\/dragosoft.info\/wp-content\/uploads\/2016\/10\/Change-root-directory-1-300x126-1.png\" alt=\"\" width=\"300\" height=\"126\" title=\"\"><\/p>\n<p>Click Save\/Save Changes . (Don't worry about the error message and try to view your blog at this point! You will probably get a message that the files were not found.)<\/p>\n<p>Move your WordPress core files to the new directory you created (WordPress).<\/p>\n<p>Copy the index.php and .htaccess files from the WordPress directory to the main directory of your website (blog). If the .htaccess file is invisible, you may need to set your FTP client to display the hidden files. If you don't use Permalinks friendly, you can do without the .htaccess file. If you are running WordPress on a (IIS) Windows server and using Friendly Permalinks, you will have a web.config instead of a .htaccess file in the WordPress root directory. For the index.php file the instructions remain the same, copy the index.php file to the root directory. However, the web.config file should be treated differently than the .htaccess file - it should be moved to the main directory..<\/p>\n<p>Open the index.php file from the main directory with your favorite text editor and make the following changes in the order you see below:<\/p>\n<p><strong>require( dirname( __FILE__ ) . '\/wp-blog-header.php' );<\/strong><\/p>\n<p>add the name of the directory you moved the main WordPress files to:<\/p>\n<p><strong>require( dirname( __FILE__ ) . '\/wordpress\/wp-blog-header.php' );<\/strong><\/p>\n<p><img decoding=\"async\" class=\"alignnone wp-image-37203 size-full\" src=\"https:\/\/dragosoft.info\/wp-content\/uploads\/2016\/10\/Change-root-directory-2-300x27-1.png\" alt=\"\" width=\"300\" height=\"27\" title=\"\"><\/p>\n<p>Now the login to the admin panel of your site will be at http:\/\/example.com\/wordpress\/wp-admin\/ as example.com is your domain name.<\/p>\n<p>If you have set up Permalinks , go to the Permalinks panel and update the permalink structure. WordPress will automatically update your .htaccess file if it has the appropriate permissions for the files. If WordPress cannot automatically overwrite them in the .htaccess file, it will show you the new rules and you will have to manually overwrite them in your .htaccess file (in the root directory where you copied the index.php file).<\/p>\n<ol start=\"2\">\n<li>\n<h2><strong>When you have installed the site from scratch in a subdirectory, but want to redirect it to the main web address - http:\/\/example.com.<\/strong><\/h2>\n<\/li>\n<\/ol>\n<p>If you already have WordPress installed in its own directory (for example, http:\/\/example.com\/wordpress ), the steps are similar to the above case:<\/p>\n<p>From the administration panel of the site Settings &gt; General &gt; in the field for <strong>WordPress URL:<\/strong> the address remains the same. Example: http:\/\/example.com\/wordpress<\/p>\n<p>In the field for <strong>URL:<\/strong> enter the URL of the root directory for example: http:\/\/example.com<\/p>\n<p><img decoding=\"async\" class=\"alignnone wp-image-37201 size-full\" src=\"https:\/\/dragosoft.info\/wp-content\/uploads\/2016\/10\/Change-root-directory-1-2-300x126-1.png\" alt=\"\" width=\"300\" height=\"126\" title=\"\"><\/p>\n<p>Click Save\/Save Changes . (Don't worry about the error message and try to view your blog at this point! You will probably get a message that the files were not found.)<\/p>\n<p>Copy the index.php and .htaccess files from the WordPress directory to your site's root directory (blog address). The login to the site admin panel remains the same http:\/\/example.com\/wordpress\/wp-admin\/<\/p>\n<p>Open the index.php file from the main directory with your favorite text editor and make the following changes in the order you see below:<\/p>\n<p>require( dirname( __FILE__ ) . '\/wp-blog-header.php' );<\/p>\n<p>add the name of the directory you moved the main WordPress files to:<\/p>\n<p>require( dirname( __FILE__ ) . '\/wordpress\/wp-blog-header.php' );<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-full wp-image-37204\" src=\"https:\/\/dragosoft.info\/wp-content\/uploads\/2016\/10\/Change-root-directory-2-300x27-2.png\" alt=\"\" width=\"300\" height=\"27\" title=\"\"><\/p>\n<p>If you have set up Permalinks , go to the Permalinks panel and update the permalink structure. WordPress will automatically update your .htaccess file if it has the appropriate permissions for the files. If WordPress cannot automatically overwrite them in the .htaccess file, it will show you the new rules and you will have to manually overwrite them in your .htaccess file (in the root directory where you copied the index.php file).<\/p>\n<p>Voila! Your site now loads from your main web address, for example http:\/\/example.com<\/p>\n<p>If you have built internal links on your site, you will need to manually revise them after all these actions.<\/p>\n<p>Keep in mind that with some of these actions your site won't be visible to users so it's nice to perform in low activity conditions, for example, in the middle of the night.<\/p>\n<p>The following links explain in detail how to change specific directories within WordPress:<\/p>\n<ul>\n<li><a href=\"https:\/\/codex.wordpress.org\/Editing_wp-config.php#Moving_wp-content_folder\" rel=\"nofollow noopener\" target=\"_blank\">Move wp-content folder<\/a><\/li>\n<li><a href=\"https:\/\/codex.wordpress.org\/Editing_wp-config.php#Moving_plugin_folder\" rel=\"nofollow noopener\" target=\"_blank\">Moving the Plugin folder<\/a><\/li>\n<li><a href=\"https:\/\/codex.wordpress.org\/Editing_wp-config.php#Moving_themes_folder\" rel=\"nofollow noopener\" target=\"_blank\">Moving the Themes folder<\/a><\/li>\n<li><a href=\"https:\/\/codex.wordpress.org\/Editing_wp-config.php#Moving_uploads_folder\" rel=\"nofollow noopener\" target=\"_blank\">Move Uploads folder<\/a><\/li>\n<\/ul>\n<p>Source: <a href=\"https:\/\/codex.wordpress.org\/Giving_WordPress_Its_Own_Directory\" rel=\"nofollow noopener\" target=\"_blank\">WordPress Codex<\/a><\/p>","protected":false},"excerpt":{"rendered":"<p>\u041f\u043e\u0432\u0435\u0447\u0435\u0442\u043e \u0445\u043e\u0440\u0430 \u0438\u0441\u043a\u0430\u0442 WordPress \u0441\u0430\u0439\u0442\u0430 \u0438\u043c \u0434\u0430 \u0441\u0435 \u0437\u0430\u0440\u0435\u0436\u0434\u0430 \u043e\u0442 \u043e\u0441\u043d\u043e\u0432\u043d\u0438\u044f \u0443\u0435\u0431 \u0430\u0434\u0440\u0435\u0441 (\u043d\u0430\u043f\u0440 http:\/\/example.com ), \u043d\u043e \u0441\u044a\u0449\u0435\u0432\u0440\u0435\u043c\u0435\u043d\u043d\u043e \u043d\u0435 \u0438\u0441\u043a\u0430\u0442 \u0446\u044f\u043b\u0430\u0442\u0430 \u0431\u044a\u0440\u043a\u043e\u0442\u0438\u044f \u043e\u0442 \u0444\u0430\u0439\u043b\u043e\u0432\u0435 \u043d\u0430 WordPress \u0434\u0430 \u0435 \u0432 \u00a0\u043e\u0441\u043d\u043e\u0432\u043d\u0430\u0442\u0430 \/root\/ \u0434\u0438\u0440\u0435\u043a\u0442\u043e\u0440\u0438\u044f. WordPress \u0432\u0438 \u043f\u043e\u0437\u0432\u043e\u043b\u044f\u0432\u0430 \u0434\u0430 \u0433\u043e \u0438\u043d\u0441\u0442\u0430\u043b\u0438\u0440\u0430\u0442\u0435 \u0432 \u043f\u043e\u0434\u0434\u0438\u0440\u0435\u043a\u0442\u043e\u0440\u0438\u044f, \u043d\u043e \u0441\u0430\u0439\u0442\u0430 \u0434\u0430 \u0441\u0435 \u0437\u0430\u0440\u0435\u0436\u0434\u0430 \u043e\u0442 \u043e\u0441\u043d\u043e\u0432\u043d\u0438\u044f \u0432\u0438 \u0443\u0435\u0431 \u0430\u0434\u0440\u0435\u0441. \u041f\u0440\u0438 \u043d\u0430\u0447\u0430\u043b\u043d\u043e\u0442\u043e \u0438\u043d\u0441\u0442\u0430\u043b\u0438\u0440\u0430\u043d\u0435 \u043d\u0430 WordPress [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":37205,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[19,74],"tags":[],"class_list":["post-24827","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-publikacii","category-wordpress-novini-i-funkcii"],"_links":{"self":[{"href":"https:\/\/dragosoft.info\/en\/wp-json\/wp\/v2\/posts\/24827","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/dragosoft.info\/en\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/dragosoft.info\/en\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/dragosoft.info\/en\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/dragosoft.info\/en\/wp-json\/wp\/v2\/comments?post=24827"}],"version-history":[{"count":0,"href":"https:\/\/dragosoft.info\/en\/wp-json\/wp\/v2\/posts\/24827\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/dragosoft.info\/en\/wp-json\/wp\/v2\/media\/37205"}],"wp:attachment":[{"href":"https:\/\/dragosoft.info\/en\/wp-json\/wp\/v2\/media?parent=24827"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/dragosoft.info\/en\/wp-json\/wp\/v2\/categories?post=24827"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/dragosoft.info\/en\/wp-json\/wp\/v2\/tags?post=24827"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}