【问题标题】:Tricky .htaccess and Drupal problem棘手的 .htaccess 和 Drupal 问题
【发布时间】:2010-09-23 11:39:29
【问题描述】:

1) 我有一个位于http://example.com 的Drupal 站点,我有一个位于http://example.com/foo 的目录,但我也有一个别名为http://example.com/foo 的Drupal 页面.如何让 Drupal 页面提供服务?目前,由于 Drupal 的 .htaccess 文件中的 Options -Indexes 声明,我得到了一个 403 禁止页面,但我不想删除它,因为我不希望目录可浏览。

编辑:我已经用以下规则解决了这个问题:

RewriteCond %{REQUEST_FILENAME} -d
RewriteRule ^(.*)$ http://localhost/s2k/index.php?q=$1 [L,QSA]

2) 让问题变得更加困难,给定相同的场景,如果我在目录 http://example.com/foo/index.html 中有一个 index.html 文件,我总是希望它优先于 Drupal 的别名页面(目前是这样 - 目前我已经修改了 .htaccess 文件,以便任何带有 index.html 文件的目录都可以显示它 - DirectoryIndex index.php index.html)。

编辑:

那么现在,我该如何编写一个 RewriteCond 来查看目录中是否有 index.html 文件?

【问题讨论】:

    标签: php drupal .htaccess


    【解决方案1】:

    我不是 RewriteRule Guru,我很确定有更好的方法来实现这一点,例如有条件的 RewriteCond。

    但只是添加

    RewriteCond %{REQUEST_URI} =/foo/
    RewriteRule ^(.*)$ index.php?q=$1 [L,QSA]
    

    在默认重写条件和规则之上,该规则适用于 /foo/ 而不是 Drupal 的默认规则。 RewriteCond %{REQUEST_FILENAME} !-d 仅在不是目录时才应用 RewriteRule。

    【讨论】:

    • 您启发了部分问题的解决方案 - 谢谢。第 2 部分有什么想法吗?
    【解决方案2】:
    RewriteCond %{REQUEST_FILENAME} -d  
    RewriteCond %{REQUEST_FILENAME}/index.html !-f
    RewriteRule ^(.*)$ http://localhost/s2k/index.php?q=$1 [L,QSA]
    

    【讨论】:

    • 多么传奇。人中之王。
    • s2k 目录从何而来?
    【解决方案3】:
    RewriteCond %{REQUEST_FILENAME}index.html -f
    RewriteRule ^(.*)$ $1index.html [L]
    
    RewriteCond %{REQUEST_FILENAME}/index.html -f
    RewriteRule ^(.*)$ $1/index.html [L]
    
    [normal Drupal rewrite rules]
    

    【讨论】:

      猜你喜欢
      • 2021-09-18
      • 1970-01-01
      • 1970-01-01
      • 2011-07-19
      • 1970-01-01
      • 1970-01-01
      • 2011-05-07
      • 2013-02-08
      • 2011-10-26
      相关资源
      最近更新 更多