Search code examples
.htaccesssvgsvgz

svg and svgz doesn't display after adding remove the trailing slash in .htaccess


Here is my .htaccess file

AddType image/svg+xml svg svgz
AddEncoding gzip svgz

Options +FollowSymlinks -MultiViews
RewriteEngine On

RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_URI}  /(.*[^/]+)/$ [NC]
RewriteRule .*              /%1         [NC,L]

RewriteCond %{REQUEST_FILENAME}      !-d
RewriteCond %{REQUEST_FILENAME}.html  -f
RewriteCond %{REQUEST_URI}   !\.html  [NC]
RewriteRule .*   %{REQUEST_URI}.html  [NC,L]

svg and svgz works fine if the web url format looks like www.myweb.com/index.html and or www.myweb.com/index

But if the url looks like this way,(a trailing slash at the end of the url) www.myweb.com/index/ text contents are fine, but unable to see svg and svgz images! Must be the .htaccess is not quite right somewhere. If someone could help? Thanks!


Solution

  • This sounds like a relative/absolute URL issue. If you're linking using relative links and you create an additional path node (the second /) which changes the relative URI base, and from that point, every relative URI will have /index/ appended to the front. You need to either change all of those URLs to absolute (start with a /) or include a relative base in the page's header:

    <base href="/" />