0

我正在尝试在我的本地 wamp 服务器上使用自适应图像。ai-cache 文件夹没有出现,图像根本没有被替换。根据这个线程,我尝试RewriteRule .(?:jpe?g|gif|png)$ test.jpg在 .htaccess 文件中并将 test.jpg 添加到同一文件夹中,但这并没有改变任何内容。

在 wamp 菜单中 Apache->Apache Modules->rewrite_module 被选中,并且在 httpd.conf 中未注释LoadModule rewrite_module modules/mod_rewrite.so

每当我更改 .htaccess 时,我都会重新启动 wamp 中的所有服务。此外,如果我asdf在顶部写它确实会给出 500 Internal Server Error 所以我知道文件正在被读取。

我究竟做错了什么?

这是位于几个子目录 (www/demos/test/) 中的 .htaccess 文件:

<IfModule mod_rewrite.c>
  Options +FollowSymlinks
  RewriteEngine On

  # Adaptive-Images -----------------------------------------------------------------------------------

  # Add any directories you wish to omit from the Adaptive-Images process on a new line, as follows:
  # RewriteCond %{REQUEST_URI} !ignore-this-directory
  # RewriteCond %{REQUEST_URI} !and-ignore-this-directory-too

  RewriteCond %{REQUEST_URI} !assets

  # don't apply the AI behaviour to images inside AI's cache folder:
  RewriteCond %{REQUEST_URI} !ai-cache

  # Send any GIF, JPG, or PNG request that IS NOT stored inside one of the above directories
  # to adaptive-images.php so we can select appropriately sized versions

  RewriteRule \.(?:jpe?g|gif|png)$ adaptive-images.php

  # END Adaptive-Images -------------------------------------------------------------------------------
</IfModule>

这是我的 httpd.conf 部分:

#
# This should be changed to whatever you set DocumentRoot to.
#
<Directory "c:/wamp/www/">
    #
    # Possible values for the Options directive are "None", "All",
    # or any combination of:
    #   Indexes Includes FollowSymLinks SymLinksifOwnerMatch ExecCGI MultiViews
    #
    # Note that "MultiViews" must be named *explicitly* --- "Options All"
    # doesn't give it to you.
    #
    # The Options directive is both complicated and important.  Please see
    # http://httpd.apache.org/docs/2.2/mod/core.html#options
    # for more information.
    #
    Options None

    #
    # AllowOverride controls what directives may be placed in .htaccess files.
    # It can be "All", "None", or any combination of the keywords:
    #   Options FileInfo AuthConfig Limit
    #
    AllowOverride all

    #
    # Controls who can get stuff from this server.
    #

#   onlineoffline tag - don't remove
    Order Deny,Allow
    Deny from all
    Allow from 127.0.0.1
    Allow from ::1:

</Directory>
4

1 回答 1

1

好吧,我知道为什么它不起作用了!这根本不是 WAMP/localhost 问题。

出于某种原因,自适应图像附带的默认 .htacess 文件并非在每种情况下都可以开箱即用。但是...我只需要添加[NC,L]到重写规则的末尾。html 和图像标记的 .jpg 扩展名为小写,但我的图像文件是用大写字母 (.JPG) 编写的,直到我在文件浏览器中打开文件扩展名时才注意到这一点。

  • nocase|NC: 使模式比较不区分大小写。
  • last|L: 立即停止重写过程,不再应用任何规则。特别注意每个目录和 .htaccess 上下文的注意事项(另请参见 END 标志)。

资源

这是最终代码:

<IfModule mod_rewrite.c>
  Options +FollowSymlinks
  RewriteEngine On

  # Adaptive-Images -----------------------------------------------------------------------------------

  # Add any directories you wish to omit from the Adaptive-Images process on a new line, as follows:
  # RewriteCond %{REQUEST_URI} !ignore-this-directory
  # RewriteCond %{REQUEST_URI} !and-ignore-this-directory-too

  RewriteCond %{REQUEST_URI} !assets

  # don't apply the AI behaviour to images inside AI's cache folder:
  RewriteCond %{REQUEST_URI} !ai-cache

  # Send any GIF, JPG, or PNG request that IS NOT stored inside one of the above directories
  # to adaptive-images.php so we can select appropriately sized versions

  RewriteRule \.(?:jpe?g|gif|png)$ adaptive-images.php [NC,L]

  # END Adaptive-Images -------------------------------------------------------------------------------
</IfModule>
于 2013-03-20T02:33:43.717 回答