【问题标题】:.htaccess with wordpress and drupal site.htaccess 与 wordpress 和 drupal 站点
【发布时间】:2012-02-10 11:07:54
【问题描述】:

在我的根 wordpress 站点中运行

我有通常的 wp-content、wp-includes、wp-admin 文件夹,但我也有我的 'drupal',它是一个 drupal 站点

我在根目录和 drupal 目录中都有 .htaccess 文件

当我尝试访问 drupal 网站的任何节点时,给出 wordpress 的 page not found 错误

请帮帮我

【问题讨论】:

    标签: wordpress .htaccess drupal


    【解决方案1】:

    在位于根目录的 .htaccess 中的 WP 规则上方添加 RewriteRule ^drupal - [L]

    【讨论】:

      【解决方案2】:

      我在 Cpanel 和 Fantastico 上看到了很多。

      https://www.drupal.org/forum/support/post-installation/2010-08-09/installing-wordpress-in-a-sub-directory-of-drupal

      这个话题很老,但仍然相关。只是想分享我对这个问题的解决方案。

      1. 在 WP 中,转到管理 > 设置 > 固定链接;

        向下滚动到 底部;你应该看到这个:

      如果您的 .htaccess 文件是可写的,我们可以自动执行此操作,但事实并非如此,因此这些是您应该在 .htaccess 文件中拥有的 mod_rewrite 规则。单击该字段并按 Ctrl+a 以全选。 将此添加到 WordPress

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

      在 Drupal 根目录中打开您的 .htaccess,然后找到这个位:

      # Pass all requests not referring directly to files in the filesystem to
        # index.php. Clean URLs are handled in drupal_environment_initialize().
        RewriteCond %{REQUEST_FILENAME} !-f
        RewriteCond %{REQUEST_FILENAME} !-d
        RewriteCond %{REQUEST_URI} !=/favicon.ico
        RewriteRule ^ index.php [L]
      

      在此下方粘贴 WP Admin 代码,从“RewriteBase”到末尾; 它现在应该可以工作了! 确保通过点击保存重置您的 WordPress 永久链接(此处的第一个 URL 将引导您完成它 - https://www.cloudways.com/blog/fix-404-error-on-wordpress/

      如果这不起作用,试试这个。

      见:

      将此添加到 WordPress

      # 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
      

      忽略 DocumentRoot 中存在的子文件夹 启用干净 URL 后,在 Drupal 根安装的子文件夹(子目录)中运行其他软件应用程序时。您的 .htaccess 文件可能会将这些 URL 重写为 Drupal。对于那些使用 Cpanel 和 Fantastico 在其域的根目录中安装 Drupal 的人来说,这可能是一个特殊的问题,其中 Fantastico 将其他软件安装到子文件夹中。例如,由 Fantastico 安装的 phpSurveyor 管理界面将无法与 Drupal 的默认 .htaccess 设置一起使用。管理界面的 URL 无法访问,并且会在您的 Drupal 站点中返回一个“找不到页面”页面。

      诀窍是修改 .htaccess 以忽略特定文件/文件夹。因此,例如,如果您有两个文件夹,并且在 Drupal 安装的根目录中,通过在 Drupal 重写之前直接在“RewriteEngine on”指令之后插入以下代码来修改您的 .htaccess 文件:

      =========[ start of .htaccess snippet]==========
      <IfModule mod_rewrite.c>
        RewriteEngine on
        #
        # stuff to let through (ignore)
        RewriteCond %{REQUEST_URI} "/folder1/" [OR]
        RewriteCond %{REQUEST_URI} "/folder2/"
        RewriteRule (.*) $1 [L]
        #
      ====================[ end ]=====================
      

      对于每个文件夹,您要绕过,添加一个 RewriteCond 行,然后用 [OR] 结束除最后一个 RewriteCond 之外的所有文件夹。请注意,重写规则中的 [L] 告诉它停止并绕过其余的重写规则。

      忽略通过 Apache Alias 指令包含的子文件夹 从 4.7 开始,在 drupal 的 .htaccess 设置中应该自动允许文件和目录通过。这就是 !-f 和 !-d 行的作用。

      但是,如果您使用的是 Apache Alias 或类似指令,则该文件实际上并不存在,因此 drupal 将按原样接管。最好的解决方法是再添加一个与您的位置匹配的条件并使其也跳过它。那是什么!方法。请看下面:

      RewriteCond %{REQUEST_URI} !^/yourDirectoryName
      RewriteCond %{REQUEST_FILENAME} !-f
      RewriteCond %{REQUEST_FILENAME} !-d
      RewriteRule ^(.*)$ index.php?q=$1 [L,QSA]
      

      这实质上意味着如果 REQUEST_URI 不以 /yourDirectoryName 开头并且 REQUEST_FILENAME 不是真实文件或真实文件夹,则应用此规则。这正是你想要的。该规则的各行之间有一个隐含的“与”。这 !说“不像这样”。

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 2018-02-10
        • 2012-06-03
        • 2021-05-03
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多