0

I am trying to install wordpress in a subfolder of an existing wordpress installation. I created a the subfolder /wp unziped a fresh Wordpress download inside of that directory and added a .htaccess with the following content:

RewriteEngine On
RewriteBase /wp/
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /wp/index.php [L]

However if I visit mysite.com/wp I get an error 404 not found. I already tried the following: Restarting Apache and adding the .htaccess content to the root .htaccess. But it did not help.

  • Have you confirmed that the /wp subdirectory is included in the WordPress config? What happens when you request example.com/wp/ (with a trailing slash)? I would expect no difference, however, if you omit the trailing slash then you are relying on mod_dir issuing a 301 redirect to append the trailing slash (which is dependent on the DirectorySlash directive). And what if you request example.com/wp/index.php directly? Again that avoids mod_dir having to issue an internal subrequest to the DirectoryIndex. So it's really just ruling our server config issues. – MrWhite May 23 at 8:07
  • @MrWhite I tried example.com/wp/index.php but I am still redirected to the theme default error 404 page. Also the request in the network tab is showing me error 404 in the header. – Mango D May 23 at 8:49
  • @MrWhite And what do you mean by "confirmed that the /wp subdirectory is included in the WordPress config"? Adding a trailing slash doesn't provide me any difference in the result. – Mango D May 23 at 8:59
  • Under WordPress "General Settings", the "WordPress Address (URL)" and "Site Address (URL)" should both include the /wp subdirectory. – MrWhite May 23 at 11:47
  • @MrWhite I cant check that because Wordpress is not installed yet. Or do you mean the root installation? I tried to add define('WP_HOME','http://new.spirigarchitektur.ch/wp'); and define('WP_SITEURL','http://new.spirigarchitektur.ch/wp');. But it did not help. – Mango D May 24 at 6:26
0

I didn't work with Apache for quite a while, so this is untested. RewriteBase is the base for your rewrite, so it's added to your rule automatically and your .htaccess should look something like this:

RewriteEngine On
RewriteBase /wp/
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . index.php [L]

Look here for further explanation: https://stackoverflow.com/questions/704102/how-does-rewritebase-work-in-htaccess

Also, you probably want to only put that in the .htaccess file inside your /wp directory.

  • There's actually no real difference between these directives and the OP's directives in the question. With the OP's directives the RewriteBase directive is redundant since the /wp subdirectory is hardcoded in the RewriteRule substitution. With your directives it will rewrite to /wp/index.php (making use of RewriteBase) - the net result is the same. In fact, in your code, the RewriteBase directive could be removed entirely (when the .htaccess file is located inside the /wp subdirectory). – MrWhite May 23 at 7:55
  • If the .htaccess is in the subdirectory, the RewriteBase does not make much sense, right. If it's in the root directory, the OP's directive would lead to rewrites that duplicate the /wp which will not work. For instance /wp/some-page would be rewritten to /wp/wp/some-page – Christopher May 23 at 14:08
  • "If the .htaccess is in the subdirectory, the RewriteBase does not make much sense, right." - it does make sense, it's just that it's not necessarily required here. "/wp/some-page would be rewritten to /wp/wp/some-page" - not with the OP's directives. The RewriteBase only applies to relative path substitutions (ie. paths that do not start with a protocol or a slash). In the OP's case the RewriteBase directive is effectively ignored since the substitution string (/wp/index.php) is not considered "relative". – MrWhite May 24 at 8:51
  • However, it transpires from comments above, that WordPress isn't actually installed yet. So, I'm not sure what is going on? – MrWhite May 24 at 8:52
  • In that case - mea culpa. I should think more before writing ... – Christopher May 24 at 15:38

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.