Htaccess重定向,但不包括图像



我试图使用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]

这将排除各种类型的图像

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

尝试:

RewriteCond %{REQUEST_URI} !.png$ [NC]

不熟悉!.前缀。检查RewriteCond Docs

Try -

RewriteCond %{REQUEST_URI} !.(ico|gif|jp?g|png|swf|rm|mov|mp?g)$ [NC]

最新更新