0

I'm sorry if this question is maybe a noob one, but I'm having some problems in correctly giving Wordpress its own directory and make it work.

I've installed WP in a subdirectory, like www.example.com/my_subdir/, and I want to access the site from www.example.com.

I've followed the instructions of the Codex page, namely on Method 1 (of course by correctly replacing my own URL's) but the site keeps on being accessed from www.example.com/my_subdir/.

This is the content of the .htaccess file inside the root directory:

<IfModule mod_rewrite.c>
RewriteEngine on
RewriteCond %{HTTP_HOST} ^(www.)?example.com$
RewriteCond %{REQUEST_URI} !^/my_subdir/
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ /my_subdir/$1
RewriteCond %{HTTP_HOST} ^(www.)?example.com$
RewriteRule ^(/)?$ my_subdir/index.php [L] 
</IfModule>

And this is the content of the .htaccess file inside the my_subdir directory:

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

How can I properly place Wordpress inside its own directory, and keep the site being accessed from the main www.example.com URL?

  • 2
    If you want it accessible from root, then you should follow the steps in Method II, not Method I – Milo Mar 26 '18 at 15:02
  • Just COPY index.php and .htaccess into www.example.com (so one folder higher then my_subdir folder itself) Edit index.php and set it like require( dirname(__FILE__) . '/my_subdir/wp-blog-header.php'); – Charles Mar 26 '18 at 17:58
  • And add also in wp-config.php (to prevent any change in the GUI admin area) define( 'WP_HOME', 'http://example.com' ); define( 'WP_SITEURL', 'http://example.com/my_subdir' ); – Charles Mar 26 '18 at 18:25
  • It seems that wasn't working because of cache not being refreshed. I have used Method I, like described in the question, and it works (so, just by creating a new .htaccess, not copying index.php, and updating the URL's in the admin area, I can access the site from www.example.com). Is this not supposed to be the correct way? – Sekhemty Mar 26 '18 at 18:27
  • I personally never add that into .htaccess (I see no reason to do) , but thats just me. I even move the wp-config.php to the root of example.com and on two sites I have that config file outside the root. Do it as you wish to do, as long it works and bring no delay/errors to the site. – Charles Mar 26 '18 at 18:39

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.