Htaccess redirects but excludes images

I am trying to use htaccess redirection to a file but cannot get the image to display.

I want to redirect any request to mydomain.com or www.mydomain.com to www.mydomain.com/test.html

This is the contents of my htaccess file:

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

I have this line of code in the test.html file:

 <img src="image.png" alt="My Image"> 

But the image doesn't display at all, I just get a broken image. I also tried using the absolute path for the image, the same thing.

+4
source share
3 answers

Try replacing the .htaccess file with the following

 # 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] 
+12
source

This excludes various types of images.

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

Try:

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

Not familiar with the prefix !. . Check RewriteCond Documents

+2
source

Source: https://habr.com/ru/post/1388201/


All Articles