运行 子文件夹中的 Drupal - 停止访问 URL 示例。com/subfolder/index.php

Running Drupal in subfolder - stop access to URL example.com/subfolder/index.php

出于与此站点主机有关的各种原因,我们是 运行 子文件夹“live”中的 Drupal 7 站点,因此 D7 的路径是 /home/username/public_html/live/

要让 Drupal 7 站点从子文件夹加载,我们在下面 /home/username/public_html 中有 .htaccess,效果很好。

RewriteEngine on
RewriteRule ^$ live/index.php [L]
RewriteCond %{DOCUMENT_ROOT}/live%{REQUEST_URI} -f
RewriteRule .* live/[=14=] [L]
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule .* live/index.php?q=[=14=] [L,QSA]

但是,如果我键入 https://website.com/live/index.php, the home page of the site loads and the URL in the location bar does not mask to https://website.com. A previous problem with a different rewrite rule caused other visitors to have reached this page and this has caused https://website.com/live/index.php 以包含在我们的 Google 分析统计信息中。

有没有办法重写 .htaccess 规则以避免 https://website.com/live/index.php 从现在开始可见? /home/username/public_html/live 处的 .htaccess 是默认的 D7 .htaccess。

答案是在 /live 文件夹中添加另一个 .htaccess 文件:

<IfModule mod_rewrite.c>
    RewriteEngine On
    RewriteCond %{THE_REQUEST} ^[A-Z]{3,}\s+\/live/index\.php\s+ [NC]
    RewriteRule ^ https://%{HTTP_HOST} [L,R=301]
</IfModule>