配置 WordPress .htaccess 以查看子文件夹

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/196500/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-08 18:29:25  来源:igfitidea点击:

Configuring WordPress .htaccess to view subfolders

wordpress.htaccess

提问by thesmallprint

I have a WordPress installation with an .htaccessfile that looks like this:

我有一个 WordPress 安装,其.htaccess文件如下所示:

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

I tried installing a fresh copy of WordPress into a subdirectory for a separate blog and am getting 404 errors within the root WordPress when I try to view it. I'm assuming this is because of the .htaccessfile.

我尝试将 WordPress 的新副本安装到一个单独的博客的子目录中,当我尝试查看它时,在根 WordPress 中出现 404 错误。我假设这是因为.htaccess文件。

How do I change it so that I can view the subfolder?

如何更改它以便我可以查看子文件夹?

回答by Sterling Hamilton

For future reference, you may want to try this:

为了将来参考,您可能想尝试以下操作:

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

回答by Owen

Edit#2: ok i think i figured this out, but it's pretty messy.

编辑#2:好的,我想我想通了,但它很乱。

modify your base wordpress install's .htaccess file to look like this:

将您的基本 wordpress 安装的 .htaccess 文件修改为如下所示:

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

now, load a new copy of wordpress into "blog2/", and copy your wp-config.phpfile over to it. edit the "/blog2/wp-config.php" file and change the $table_prefixto something different than your first blog. (this will install both wordpresses into the same database).

现在,将 wordpress 的新副本加载到“blog2/”中,并将您的wp-config.php文件复制到其中。编辑“/blog2/wp-config.php”文件并将其更改为$table_prefix与您的第一个博客不同的内容。(这会将两个 wordpress 安装到同一个数据库中)。

once you've done that, you should be able to go to:

完成后,您应该可以访问:

http://yourdomain.com/blog2/

and finish up the installation without issue. the initial problem was that the new copy of wordpress kept trying to use the first copy's wp-config.phpfile. moving it over manually fixed that all up.

并顺利完成安装。最初的问题是 wordpress 的新副本不断尝试使用第一个副本的wp-config.php文件。手动移动它修复了所有问题。

because i'm insane, i tested this with two fresh copies, wrote a few test articles, and was able to navigate around without issue, so it should work :)

因为我疯了,我用两个新副本测试了这个,写了一些测试文章,并且能够毫无问题地导航,所以它应该可以工作:)