【问题标题】:WAMP mod_rewrite RewriteRule not workingWAMP mod_rewrite RewriteRule 不起作用
【发布时间】:2023-04-05 17:30:02
【问题描述】:

我正在尝试在我的本地 wamp 服务器上使用 adaptive images。 ai-cache 文件夹没有显示,并且图像根本没有被替换。根据this thread,我在.htaccess 文件中尝试了RewriteRule .(?:jpe?g|gif|png)$ test.jpg,并在同一文件夹中添加了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>

【问题讨论】:

  • 有一个类似的问题解决了here。

标签: .htaccess mod-rewrite wamp wampserver file-extension


【解决方案1】:

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

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

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

Source

这是最终代码:

<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>

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2012-10-10
    • 2013-04-26
    • 1970-01-01
    • 1970-01-01
    • 2014-01-11
    • 1970-01-01
    • 1970-01-01
    • 2014-05-24
    相关资源
    最近更新 更多