无法访问子目录上的新WP安装

时间:2017-12-06 作者:Rick Alvarez

我遇到了这个问题:我在root上安装了一个WP。到目前为止还不错。

现在我正在一个子目录上安装另一个版本,但它不起作用。我以前做过很多次,但可能是因为服务器配置,可能是新的WP版本发生了一些变化,在这种情况下不起作用。它不会创建永久链接(我已经检查了权限),如果我使用自定义结构,它会转到主安装并显示其404页面。然而,如果我将永久链接设置为普通,它的显示就很好。

我注意到的另一件事是,如果我尝试自定义网站,它会要求我登录,因为我的会话已经完成。不管我尝试登录多少次,它都会把我踢出去。

以防万一,WordPress地址(URL)和网站地址(URL)是正确的,没有尾部斜杠,但它们看起来是灰色的。我还向wp\\u config添加了以下行。php无效

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
不管怎样,我花了最后几个小时在这里和其他来源上检查文档和类似的问题,但什么都不管用,我完全迷路了。你知道我做错了什么吗?或者我能做些什么来迫使这一切正常运转?

编辑我看到根目录上的wp配置文件添加了此代码,不知道这是否重要,但添加它只是以防万一(IP地址已编辑):

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);
}
和。根目录上的htaccess文件:

#<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 ##

1 个回复
SO网友:kierzniak

从您的评论中,我知道您正在使用nginx。Nginx需要与Apache稍有不同的配置。可能您当前的nginx vhost就是这样。

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;
  }
}
此配置的关键部分是:

location / {
  # try to serve file directly, fallback to index.php
  try_files $uri $uri/ /index.php?$args;
}
它告诉我们这样的事情:

对于以开头的位置/ 字符尝试从文件系统加载文件,若并没有这样的文件,则重写为索引。带有参数的php。

所以,这就是为什么当你试图访问你的subdir站点时,它正在为以下内容工作/subdir/index.php?p=100 因为文件/subdir/index.php 存在,因此无需重定向。然而,当您尝试访问/subdir/lorem-ipsum/ 您将被重定向到主页,因为没有/subdir/lorem-ipsum/ 文件

root和subdir WordPress安装的正确配置为:

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;
  }
}
注:Nginx不在乎。htaccess您可以删除它。

结束

相关推荐

Let me choose permalinks

我需要选择一个叫做“mysite”的永久链接。com/1418”,但wordpress不断在永久链接中添加“-2”。通常这意味着我已经有了一个名为“相同”的页面,它位于垃圾箱或其他地方。但这里的情况似乎并非如此。我尝试在设置中重置永久链接,这也没有帮助。我如何使用数字作为页面名称permalink,而不用wordpress在permalink中添加“-2”。