0

I'm having this issue: I have a WP install on root. So far so good.

Now I'm installing another version on a subdirectory, and it doesn't work. I have done this many times before, but maybe because of a server configuration, maybe something changed on new WP versions, it doesn't work in this case. It doesn't create permalinks (I have checked permissions) and if I use a custom structure, it goes to the main install and displays its 404 page. However, if I set permalinks as plain, it displays just fine.

Another thing I noticed is that if I try to customize the site, it asks me to log in because my session has finished. No matter how many times I try to log in, it kicks me out.

Just in case, WordPress Address (URL) and Site Address (URL) are correct, with no trailing slash, but they look grayed out. I also added the following lines to wp_config.php to no avail

define('WP_HOME','https://www.example.com/landing');  // NO trailing slash at the end
define('WP_SITEURL','https://www.example.com/landing'); // NO trailing slash at the end

Anyways, I spent the last hours checking documentation and similar questions here and on other sources, but nothing works and I'm completely lost. Any idea on what am I doing wrong, or what can I do to force this to work?

EDIT

I see that the wp-config file on root has this code added, don't know if it matters, but adding it just in case (IP address edited):

if( ini_get("max_input_vars") < 5000)
{
    echo "Set max_input_vars upto 5000";
    exit;
}

if($_SERVER['REMOTE_ADDR'] == '123.123.123.123')
{
    define('DISALLOW_FILE_MODS',false);
}
else
{ 
    define('DISALLOW_FILE_MODS',false);
}

and .htaccess file on root:

#<FilesMatch ".(eot|ttf|otf|woff|css|js|svg)">
#    Header set Access-Control-Allow-Origin "*"
#    </FilesMatch>
Header set Access-Control-Allow-Origin "https://beta.example.com"
# Block WordPress xmlrpc.php requests
<Files xmlrpc.php>
order deny,allow
deny from all
allow from 111.111.111.33
allow from 206.111.111.184
allow from 206.111.111.185
allow from 127.0.0.1
</Files>
RewriteCond %{REQUEST_METHOD} ^(TRACE|TRACK)
RewriteRule .* - [F]

php_value max_input_vars 5000 

# 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


<IfModule mod_headers.c>
    ExpiresActive On
    ExpiresDefault A29030400
    <FilesMatch "\.(jpg|jpeg|gif|png|js|css)$">
      ExpiresDefault A7200 
      Header append Cache-Control "private, must-revalidate"
    </FilesMatch>
</IfModule>

AddOutputFilterByType DEFLATE text/plain
#AddOutputFilterByType DEFLATE text/html
AddOutputFilterByType DEFLATE text/xml
AddOutputFilterByType DEFLATE text/css
AddOutputFilterByType DEFLATE application/xml
AddOutputFilterByType DEFLATE application/xhtml+xml
AddOutputFilterByType DEFLATE application/rss+xml
AddOutputFilterByType DEFLATE application/javascript
AddOutputFilterByType DEFLATE application/x-javascript

<Files *.htm>
    #Compress
    SetOutputFilter DEFLATE
</Files>

# start Emerson adds

# Protect wp-config.php file
<files wp-config.php>
order allow,deny
deny from all
</files>

# Block the include-only files
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteRule ^wp-admin/includes/ - [F,L]
RewriteRule !^wp-includes/ - [S=3]
RewriteRule ^wp-includes/[^/]+.php$ - [F,L]
RewriteRule ^wp-includes/js/tinymce/langs/.+.php - [F,L]
RewriteRule ^wp-includes/theme-compat/ - [F,L]
</IfModule>

# Prevent people from browsing the content of your directories
Options All -Indexes

# Protect the .htaccess file itself
<Files .htaccess>
order allow,deny
deny from all
</Files>

# block ip addresses from login to the site
# order allow,deny
# deny from 456.123.8.9
# allow from all

## EXPIRES CACHING ##
<IfModule mod_expires.c>
ExpiresActive On
ExpiresByType image/jpg "access 1 year"
ExpiresByType image/jpeg "access 1 year"
ExpiresByType image/gif "access 1 year"
ExpiresByType image/png "access 1 year"
ExpiresByType text/css "access 1 month"
ExpiresByType application/pdf "access 1 month"
ExpiresByType text/x-javascript "access 1 month"
ExpiresByType application/x-shockwave-flash "access 1 month"
ExpiresByType image/x-icon "access 1 year"
ExpiresDefault "access 2 days"
</IfModule> 
## EXPIRES CACHING ##
  • You've "done this many times before", on the same server or on different servers? BTW, what is the type of server you are using? Apache or Nginx? – hcheung Dec 6 '17 at 2:33
  • @hcheung, I did it on other servers, this is the first time it happens to me, so I think it might be related to the server or maybe a configuration on wp-config on root made by another person (see edit). This server is running on Nginx – Rick Alvarez Dec 6 '17 at 16:55
  • That's what I suspected. .htaccess is not used in nginx. Check with your hosting company on where the nginx.conf and virtual-server config (it usually in /etc/nginx/site-available/ file located and add the location directive and server_name for your subdirectory as suggested by @motivast. You probably don't need to change the rest of the nginx.conf and virtual-server config. – hcheung Dec 7 '17 at 0:13
  • This link may help you on settings. – hcheung Dec 7 '17 at 0:28
0

From your comment I know that you are using nginx. Nginx need a bit different configuration than Apache. Probably your current nginx vhost looks like that.

server {
  listen *:80;
  server_name           test.dev;
  root                  /var/www/test;

  access_log            /var/log/nginx/access.log;
  error_log             /var/log/nginx/error.log;

  index index.php index.html;

  location / {
    # try to serve file directly, fallback to index.php
    try_files $uri $uri/ /index.php?$args;
  }

  location ~ \.php$ {

    include fastcgi.conf;

    fastcgi_pass 127.0.0.1:9070;
  }
}

The key part of this configuration is:

location / {
  # try to serve file directly, fallback to index.php
  try_files $uri $uri/ /index.php?$args;
}

it tell us something like that:

For location beginning with / character try to load file from file system and if there is no such a file rewrite to index.php with arguments.

So thats why when you are trying to visit your subdir site it is working for something like /subdir/index.php?p=100 because file /subdir/index.php is existing so there is no need for redirection. However when you try to visit /subdir/lorem-ipsum/ you will be redirect to home because there is no /subdir/lorem-ipsum/ file.

Correct configuration for both root and subdir WordPress installation will be:

server {
  listen *:80;
  server_name           test.dev;
  root                  /var/www/test;

  access_log            /var/log/nginx/access.log;
  error_log             /var/log/nginx/error.log;

  index index.php index.html;

  location / {
    # try to serve file directly, fallback to index.php
    try_files $uri $uri/ /index.php?$args;
  }

  location /subdir {
     # try to serve file directly, fallback to index.php
     try_files $uri $uri/ /subdir/index.php?$args;
  }

  location ~ \.php$ {

    include fastcgi.conf;

    fastcgi_pass 127.0.0.1:9070;
  }
}

PS. Nginx doesn't care about .htaccess you can remove it.

  • I only have an nginx.conf file on root which only includes w3tc browser cache, nothing else. Is this the file you mean? If so, it didn't work; I assume /subdir/ has to be changed to my subdirectory name, right? or should it use subdir just as you posted?. I also changed root values to mine. Again, not sure if I'm doing things right or if this is the correct file – Rick Alvarez Dec 6 '17 at 19:03
  • aaaah, doing a search I see I need to restart nginx as well. Will try with the SysAdmin since I have no access to that and let you know – Rick Alvarez Dec 6 '17 at 19:06
  • Do you use dedicated server, vps or hosting? Do you have root access to server? Which hosting provider do you use? You should be searching for config with server_name yoursitedomain.com; – kierzniak Dec 6 '17 at 19:07

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.