htaccess重定向但排除图像

use*_*494 4 .htaccess redirect image

我正在尝试使用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
Run Code Online (Sandbox Code Playgroud)

我在test.html文件中有这行代码:

<img src="image.png" alt="My Image">
Run Code Online (Sandbox Code Playgroud)

但是图像根本没有显示,我只是得到了破碎的图像.我也尝试使用绝对路径的图像,同样的事情.

Ulr*_*lha 15

尝试使用以下内容替换.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]
Run Code Online (Sandbox Code Playgroud)


Rin*_*rge 5

这将排除各种类型的图像

#if the request does not end with .gif,.png or jpg 
RewriteCond %{REQUEST_URI} !(\.gif|\.jpg|\.png)$ [NC]
RewriteRule ^index.html$ index.php [NC] 
Run Code Online (Sandbox Code Playgroud)