AskOverflow.Dev

AskOverflow.Dev Logo AskOverflow.Dev Logo

AskOverflow.Dev Navigation

  • 主页
  • 系统&网络
  • Ubuntu
  • Unix
  • DBA
  • Computer
  • Coding
  • LangChain

Mobile menu

Close
  • 主页
  • 系统&网络
    • 最新
    • 热门
    • 标签
  • Ubuntu
    • 最新
    • 热门
    • 标签
  • Unix
    • 最新
    • 标签
  • DBA
    • 最新
    • 标签
  • Computer
    • 最新
    • 标签
  • Coding
    • 最新
    • 标签
主页 / server / 问题 / 813919
Accepted
ReynierPM
ReynierPM
Asked: 2016-11-09 19:48:32 +0800 CST2016-11-09 19:48:32 +0800 CST 2016-11-09 19:48:32 +0800 CST

.htaccess 在 WP 网站正常工作时阻止网站工作,为什么?

  • 772

我有三个站点在具有专用 IP 地址的共享主机 (Bluehost) 中运行。说明如下:

  • example.com=> 这是主站点和域,是一个 WP
  • example.net=> 这是一个附加域(不知道你是否熟悉这个术语)并且正在运行另一个 WP 站点
  • subsite.example.net=> 这是一个独立的 PHP 应用程序

每个 WP 都有自己的.htacess文件,如下所示:

# 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文件,两个 WP 站点都可以正常工作,但独立应用程序不能。如果我删除.htaccess文件,则相反,独立应用程序可以工作,但 WP 网站不能。

任何人都可以帮助我找到解决此问题的方法吗?

更新

我正在.htaccess为独立 PHP 应用程序的文件使用以下配置:

<IfModule mod_rewrite.c>
    RewriteEngine on
    RewriteBase /
    RewriteRule ^index\.php$ - [L]
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteRule . index.php [L]

    # Add Caching.
    <FilesMatch ".(ico|jpg|jpeg|png|gif|js|css|swf)$">
        Header set Cache-Control "max-age=10800"
    </FilesMatch>

    # Prevent viewing of htaccess file.
    <Files .htaccess>
        order allow,deny
        deny from all
    </Files>

    # Prevent directory listings
    Options All -Indexes

    # Compress text, html, javascript, css, xml:
    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
</IfModule>

但不工作,因为我一点击任何链接就被踢出应用程序。

独立站点位于/public_html/plataformaWP 位于/public_html. 为什么我在这一点上做错了?

.htaccess mod-rewrite apache2 rewritecond
  • 2 2 个回答
  • 301 Views

2 个回答

  • Voted
  1. Sukhjinder Singh
    2016-11-09T22:53:36+08:002016-11-09T22:53:36+08:00

    为您的独立 PHP 应用程序创建.htaccess文件,将您的代码重定向到subsite.example.net

    • 2
  2. Best Answer
    MrWhite
    2016-11-10T02:03:53+08:002016-11-10T02:03:53+08:00

    重要的是底层文件/目录结构。如果这 3 个站点基本上在同一个帐户上 - 同一个父目录 - 那么每个站点可能位于一个单独的子目录中(这通常是插件和子域在共享环境中默认的方式)并且您应该.htaccess在每个子目录中有一个单独的文件。不是所有人。

    更新#1:尝试向 WordPress 添加一个例外,.htaccess以明确排除通过子域访问的任何重写。例如:

    # BEGIN WordPress
    <IfModule mod_rewrite.c>
        RewriteEngine On
        RewriteBase /
        RewriteRule ^index\.php$ - [L]
    
        RewriteCond %{HTTP_HOST} !^subsite\.example\.net$ [NC]
        RewriteCond %{REQUEST_FILENAME} !-f
        RewriteCond %{REQUEST_FILENAME} !-d
        RewriteRule . /index.php [L]
    </IfModule>  
    # END WordPress
    

    但是,这确实不是必需的,因为(如评论中所述),独立应用程序.htaccess文件中的 mod_rewrite 指令应该完全覆盖这些指令(因为独立应用程序位于子目录中)。

    向WordPress块添加代码的另一个警告是,这可能会被下一次更新覆盖。

    更新#2:或者,尝试将RewriteOptions指令添加到独立应用程序的.htaccess文件(位于子目录中):

    <IfModule mod_rewrite.c>
        RewriteEngine on
        RewriteOptions IgnoreInherit
        :
    

    如果这可行,那么似乎表明RewriteOptions InheritDown[Before]服务器配置中有一个指令允许继承父目录中的 mod_rewrite 指令。注意IgnoreInherit和InheritDown[Before]是 A​​pache 2.4+ 的特性。

    (编辑:似乎 OP 在 Apache 2.2.31 上,因此上述指令会导致 500 Internal Server 错误。)

    更新#3:您还可以尝试RewriteBase /从两个文件中删除指令.htaccess并删除 WordPressRewriteRule 替换中的斜杠前缀以匹配独立应用程序.htaccess文件中的规则。因此,WordPress.htaccess文件变为:

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

    之前读过的最后一行:(RewriteRule . /index.php [L]即带有斜杠前缀)。斜杠表示相对于根的 URL 路径,没有斜杠它现在是相对于包含.htaccess文件的目录的。

    • 2

相关问题

  • apache重写以将文件夹分配给域

  • Apache conf 或 .htaccess 规则将 404 重定向到特定文件类型的另一个位置

  • 如何让 Apache2 重定向到子目录

  • .htaccess - 删除所有 cookie

  • 我的 .htaccess 文件是什么意思?

Sidebar

Stats

  • 问题 205573
  • 回答 270741
  • 最佳答案 135370
  • 用户 68524
  • 热门
  • 回答
  • Marko Smith

    新安装后 postgres 的默认超级用户用户名/密码是什么?

    • 5 个回答
  • Marko Smith

    SFTP 使用什么端口?

    • 6 个回答
  • Marko Smith

    命令行列出 Windows Active Directory 组中的用户?

    • 9 个回答
  • Marko Smith

    什么是 Pem 文件,它与其他 OpenSSL 生成的密钥文件格式有何不同?

    • 3 个回答
  • Marko Smith

    如何确定bash变量是否为空?

    • 15 个回答
  • Martin Hope
    Tom Feiner 如何按大小对 du -h 输出进行排序 2009-02-26 05:42:42 +0800 CST
  • Martin Hope
    Noah Goodrich 什么是 Pem 文件,它与其他 OpenSSL 生成的密钥文件格式有何不同? 2009-05-19 18:24:42 +0800 CST
  • Martin Hope
    Brent 如何确定bash变量是否为空? 2009-05-13 09:54:48 +0800 CST
  • Martin Hope
    cletus 您如何找到在 Windows 中打开文件的进程? 2009-05-01 16:47:16 +0800 CST

热门标签

linux nginx windows networking ubuntu domain-name-system amazon-web-services active-directory apache-2.4 ssh

Explore

  • 主页
  • 问题
    • 最新
    • 热门
  • 标签
  • 帮助

Footer

AskOverflow.Dev

关于我们

  • 关于我们
  • 联系我们

Legal Stuff

  • Privacy Policy

Language

  • Pt
  • Server
  • Unix

© 2023 AskOverflow.DEV All Rights Reserve