【问题标题】:wordpress site ignoring sub directory when htaccess present当 htaccess 存在时,wordpress 站点忽略子目录
【发布时间】:2023-03-15 20:03:01
【问题描述】:

首先我没有设置我目前正在开发的网站,而且我对 wordpress 设置不是很熟悉。我被要求在他们的网站上添加一个管理部分到这个使用 Wordpress 配置的网站。如果我添加一个子目录,我可以通过 web 访问子目录就好了。当我将 .htaccess 添加到该子目录以进行身份​​验证时,问题就来了。当我这样做并尝试访问子目录时,它会出错为“找不到页面”。

有人可以帮忙吗?我认为它与下面提供的 Wordpress .htaccess 文件有关:

# 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


更新

当子目录中的.htaccess为空时,我可以通过web访问子目录就好了。 子目录中的.htaccess(填写时)如下:

AuthType Basic
AuthName "Sphere"
AuthUserFile "/path/to/htpasswd"
require valid-user

【问题讨论】:

    标签: wordpress .htaccess directory subdirectory


    【解决方案1】:

    在其他地方找到了我的问题的解决方案。编辑根 .htaccess(用于 wordpress)以匹配以下内容应该可以解决同样遇到此问题的任何人:

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

    【讨论】:

      【解决方案2】:

      我刚刚根据您的问题测试了一个设置。这是我在您的帖子中收集到的层次结构示例:

      public_html/ (all WP install files here)
      public_html/admin/ (here I created a new folder similar to your question)
      public_html/admin/index.php (test file - just echos a line of text)
      public_html/admin/.htaccess (currently blank)
      

      所以我在从 WP 根目录生成的新子目录中的 .htaccess 是空白的。我不确定那里会/应该有什么样的身份验证。如果我访问“网站/管理员/” - 测试行回声就好了。我没有看到任何 404。

      您能否提供更多细节,以便我可以尝试更好地复制您看到的问题?

      【讨论】:

      • 感谢您的回复。不幸的是,它又做了同样的事情。我只是设置了一个名为 sphere 的新目录,当我在没有 htaccess 的情况下执行此操作时,它在转到目录 www.site.com/sphere 时工作正常。但是,当添加 htaccess 时,它再次出错。这是子目录中的 htaccess:AuthType Basic AuthName "Sphere" AuthUserFile "my_htpasswd/path" require valid-user
      • 顺便说一句,您的回答有助于确定它是子目录 htaccess 文件中的特定内容,而不是 .htaccess 文件本身的存在。感谢您的帮助!
      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2017-10-18
      • 1970-01-01
      • 2015-05-30
      • 2015-12-30
      • 2012-09-16
      相关资源
      最近更新 更多