image - htaccess 重定向但排除图像

标签 image .htaccess redirect

我正在尝试使用 htaccess 重定向到文件,但无法显示图像。

我想将任何请求重定向到 mydomain.com 或 www.mydomain.com 到 www.mydomain.com/test.html

这是我的 htaccess 文件的内容:

# Turn rewriting on
Options +FollowSymLinks
RewriteEngine On
RewriteCond %{REQUEST_URI} !=/test.html
RewriteCond %{REQUEST_URI} !=*\.png$ [NC]
RewriteRule .* /test.html

我的 test.html 文件中有这行代码:
<img src="image.png" alt="My Image">

但是图像根本不显示,我只是得到一个损坏的图像。我也尝试使用图像的绝对路径,同样的事情。

最佳答案

尝试用以下内容替换您的 .htaccess 文件

# Turn rewriting on
Options +FollowSymLinks
RewriteEngine On
RewriteBase /

#if the request does not end with test.html or is not a .png
RewriteCond %{REQUEST_URI} !(test\.html|\.png)$ [NC]
# Rewrite it to test.html
RewriteRule .* /test.html  [L]

关于image - htaccess 重定向但排除图像,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8649456/

相关文章:

html - 列数 : auto CSS makes images disappear after 1 column

wordpress - 在 wordpress .htaccess 中将特定页面从 http 重定向到 https

python - Google App Engine 在按钮点击时重定向到用户登录

c# - 如何使用 "www"URL 重定向到没有 "www"URL,反之亦然?

android - 每次单击按钮时将图像旋转 90,180,270 度和 360 度,并在纵向和横向模式下保持旋转度数?

html - 如何才能得到完美的方形图像而不失真

javascript - 修复当站点移动到子目录时 Assets 的 "/"(根)引用

Magento 支付模块,如 PayPal(外部 URL 重定向)

c# - 在 C# 中使用 GDCM 库加载 DICOM 图像并转换为 System.Windows.Control.Image

file - 试图隐藏 .htaccess 文件