【问题标题】:.htaccess rewrite with drupal and clean urls only partially works?.htaccess 用 drupal 和干净的 url 重写只能部分工作?
【发布时间】:2011-04-17 20:46:32
【问题描述】:

大家好,我在 MAMP(Mac OSX、Apache、MySQL、Php)堆栈上运行 Drupal 时遇到异常访问问题。 Drupal 安装工作正常,所以我知道这不是 Drupal 问题。 “干净的 URL”适用于任何具有单级 url,但没有 2+ 路径级别的东西。

例如:

example.com/foo、example.com/bar 等都可以完美运行。

example.com/foo/bar、example.com/bar/foo/bar 等。工作。

我得到一个由 Drupal 提供的访问被拒绝(不是 404)页面,带有登录框和站点名称,但没有应用主题。 (而且,是的,我以管理员/用户 1 的身份积极登录);)

如果我禁用“干净的 url”,一切都会完美运行。我假设这与我在 htaccess 中的重写规则有关,但在网上搜索无济于事(包括 drupal 的站点和 irc 频道)。

我目前的.htaccess如下:

#
# Apache/PHP/Drupal settings:
#

# Protect files and directories from prying eyes.
<FilesMatch "\.(engine|inc|info|install|make|module|profile|test|po|sh|.*sql|theme|tpl(\.php)?|xtmpl|svn-base)$|^(code-style\.pl|Entries.*|Repository|Root|Tag|Template|all-wcprops|entries|format)$">
  Order allow,deny
</FilesMatch>


# Don't show directory listings for URLs which map to a directory.
Options -Indexes

# Follow symbolic links in this directory.
Options +FollowSymLinks

# Make Drupal handle any 404 errors.
ErrorDocument 404 /index.php

# Force simple error message for requests for non-existent favicon.ico.
<Files favicon.ico>
  # There is no end quote below, for compatibility with Apache 1.3.
  ErrorDocument 404 "The requested file favicon.ico was not found.
</Files>

# Set the default handler.
DirectoryIndex index.php

# Override PHP settings. More in sites/default/settings.php
# but the following cannot be changed at runtime.

# PHP 4, Apache 1.
<IfModule mod_php4.c>
  php_value magic_quotes_gpc                0
  php_value register_globals                0
  php_value session.auto_start              0
  php_value mbstring.http_input             pass
  php_value mbstring.http_output            pass
  php_value mbstring.encoding_translation   0
</IfModule>

# PHP 4, Apache 2.
<IfModule sapi_apache2.c>
  php_value magic_quotes_gpc                0
  php_value register_globals                0
  php_value session.auto_start              0
  php_value mbstring.http_input             pass
  php_value mbstring.http_output            pass
  php_value mbstring.encoding_translation   0
</IfModule>

# PHP 5, Apache 1 and 2.
<IfModule mod_php5.c>
  php_value magic_quotes_gpc                0
  php_value register_globals                0
  php_value session.auto_start              0
  php_value mbstring.http_input             pass
  php_value mbstring.http_output            pass
  php_value mbstring.encoding_translation   0
</IfModule>

# Requires mod_expires to be enabled.
<IfModule mod_expires.c>
  # Enable expirations.
  ExpiresActive On

  # Cache all files for 2 weeks after access (A).
  ExpiresDefault A1209600

  <FilesMatch \.php$>
    # Do not allow PHP scripts to be cached unless they explicitly send cache
    # headers themselves. Otherwise all scripts would have to overwrite the
    # headers set by mod_expires if they want another caching behavior. This may
    # fail if an error occurs early in the bootstrap process, and it may cause
    # problems if a non-Drupal PHP file is installed in a subdirectory.
    ExpiresActive Off
  </FilesMatch>
</IfModule>

# Various rewrite rules.
<IfModule mod_rewrite.c>
  RewriteEngine on

  # If your site can be accessed both with and without the 'www.' prefix, you
  # can use one of the following settings to redirect users to your preferred
  # URL, either WITH or WITHOUT the 'www.' prefix. Choose ONLY one option:
  #
  # To redirect all users to access the site WITH the 'www.' prefix,
  # (http://example.com/... will be redirected to http://www.example.com/...)
  # adapt and uncomment the following:
  # RewriteCond %{HTTP_HOST} ^example\.com$ [NC]
  # RewriteRule ^(.*)$ http://www.example.com/$1 [L,R=301]
  #
  # To redirect all users to access the site WITHOUT the 'www.' prefix,
  # (http://www.example.com/... will be redirected to http://example.com/...)
  # uncomment and adapt the following:
  # RewriteCond %{HTTP_HOST} ^www\.example\.com$ [NC]
  # RewriteRule ^(.*)$ http://example.com/$1 [L,R=301]

  # Modify the RewriteBase if you are using Drupal in a subdirectory or in a
  # VirtualDocumentRoot and the rewrite rules are not working properly.
  # For example if your site is at http://example.com/drupal uncomment and
  # modify the following line:
  # RewriteBase /drupal
  #
  # If your site is running in a VirtualDocumentRoot at http://example.com/,
  # uncomment the following line:
  RewriteBase /

  # Rewrite URLs of the form 'x' to the form 'index.php?q=x'.
  RewriteCond %{REQUEST_FILENAME} !-f
  RewriteCond %{REQUEST_FILENAME} !-d
  RewriteCond %{REQUEST_URI} !=/favicon.ico
  RewriteRule ^(.*)$ index.php?q=$1 [L,QSA]
</IfModule>

# $Id: .htaccess,v 1.90.2.5 2010/02/02 07:25:22 dries Exp $

任何帮助将不胜感激。谢谢,TE

【问题讨论】:

  • 对于 Drupal 发出的 403 响应,Drupal 日志中应该有条目显示发出 403 的请求。此请求将是已经重写的版本,而不是初始的干净 URL。这些条目对您失败的请求有何影响?
  • @Henrik - 这是来自 drupal 日志的“拒绝访问”条目之一:详细信息/类型:拒绝访问/日期:2010 年 9 月 23 日星期四 - 15:52/用户:匿名/位置:127.0.0.1:8080/admin/settings/clean-urls / 推荐人:127.0.0.1:8080/?q=admin/settings/clean-urls / 消息:admin/settings/clean-urls / 严重性:警告 / 主机名:127.0.0.1 / 操作

标签: drupal .htaccess mod-rewrite mamp


【解决方案1】:

您可能有一个破坏的 RewriteBase,看起来您正在尝试使用 VirtualDocumentRoot 托管网站,但您使用的是子目录而不是子域。因此,如果您希望站点位于 /foo 或 /bar,那么 RewriteBase 需要是 /foo 或 /bar。将其设置为 / 仅在您可以以某种方式使用 dns 技巧来定向到域或子域时才有效。

在我们的办公室里,我们每个人都有site-folder.computer.fake-domain.com 和一个位于我们和互联网之间的 dns 服务器。因此,如果我创建一个名为 foo 的文件夹,我将能够在 foo.computer.fake-domain.com/ 而不是 localhost/foo 访问它

【讨论】:

  • 不幸的是,我的公司不允许我们访问 .hosts 文件,所以花哨的 dns 诡计可能对我不起作用。 ;) 但是,是的,我认为这很可能是一个 rewritebase 问题——但我不知道如何解决它。基本的 drupal 文件在 apache 的 doc-root 中,而不是在该根的子文件夹中 - 在我的情况下(对于 mamp 堆栈)它是 htdocs 文件夹(?)
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2016-04-24
  • 2014-03-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多