我正在尝试使用 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/