1

I've given WordPress it's own directory in mysite/wordpress to try out some security things.

Using a WAMP on Localhost, I changed httpd.conf to:

  DocumentRoot "${INSTALL_DIR}/www/mysite
 <Directory "${INSTALL_DIR}/www/mysite/">

and httpd-vhosts.conf to:

   DocumentRoot "${INSTALL_DIR}/www/mysite"
  <Directory "${INSTALL_DIR}/www/mysite/">

When I go to localhost, it says /index of /wordpress.

How do I get apache to serve the actual files (WordPress) inside the sub-directory?

0

Why don't you use WordPress core settings for doing this? This is the recommended way and doesn't need editing .htaccess or Apache config directly. You can find the details here in WP docs. I'm posting the steps here:

  • After installing WP in the root dir, Go to the Settings->General and change these values:
  • WordPress Address (URL): http://localhost/wordpress
  • Site Address (URL): http://localhost
  • Save the settings and don't worry about the errors
  • Move all WP files to the wordpress sub-directory.
  • Copy (NOT MOVE!) the index.php and .htaccess files from the wordpress sub-directory into the root directory of your site
  • Edit the index.php placed in the root and change the line that says: require( dirname( __FILE__ ) . '/wp-blog-header.php' ); to the following: require( dirname( __FILE__ ) . '/wordpress/wp-blog-header.php' );
  • Login to WP using http://localhost/wordpress/wp-admin/
  • Go to the Settings->Permalinks and save the settings (with no edit). This will regenerate .htaccess file in the sub-directory to include /wordpress path in it)

Now everything should work fine.

UPDATE: When you save the Permalinks, .htaccess file in the sub-directory would be something like this:

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

# END WordPress

And .htaccess in the root directory:


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

# END WordPress

Note the differences in RewriteBase rule and the last RewriteRule rule. By adding these lines, WP would tell Apache, how to load the website by accessing the root directory of localhost (in addition to the edit in the root index.php). These .htaccess files are the reason that there's is no need to re-configure Apache.

UPDATE2: I usually use XAMPP on Windows, and Apache rewrite_module is activated bu default on it. Digging around WAMP, I found that this module isn't activated by default on WAMP. This may be the reason .htaccess files are not working on your setup. See these links to activate this module. [1] , [2]

I hope this would help you.

  • This works, only if I change apache's httpd.conf and httpd-vhosts.conf to serve my document root in to www/mysite folder first. Tried your way without first doing this and it wouldn't serve the site files to localhost without first pointing to it in apache configuration. Thanks! – West Jun 15 at 18:26
  • It's unusual. Did you copy index.php and .htaccess to root and edit the header in the index and saved the permas? As I said, It's possible to this without editing Apache conf. Those two .htaccess files tell Apache to load the site from sub-dir see this: shot I'll update the answer with details on .htaccess files. anyway, glad it helped – Yashar Jun 15 at 19:06
  • see my second update – Yashar Jun 15 at 19:33
  • without telling apache on WAMP which file to serve, it gives me a WAMP configuration-like page and doesn't let me log in. When I tell it to serve /www/mysite it automatically does the first step you mentioned, wordpress url: /wordpress and then I just change localhost/ and it works! – West Jun 15 at 20:03
  • As I mentioned in my second update, you have to enable rewrite_module to do it without re-configuring Apache and in this case, if you got stuck at login after changing the addresses, use /wp-login.php instead of /wp-admin and save Permalinks after logged in. – Yashar Jun 15 at 20:12

Your Answer

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

Not the answer you're looking for? Browse other questions tagged or ask your own question.