johnbumble johnbumble - 3 months ago 28
Apache Configuration Question

Eliminating multiple file extensions .htaccess

I am trying to eliminate the file extensions, but can only eliminate one at a time. So my goal is to eliminate the extensions .jpeg, .png, .jpg.

My Code (eliminates the .png extension)

#removes .png file extension
RewriteEngine On

RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^([^\.]+)$ $1.png [NC,L]


What I tried (NOT WORKING, only removes the first .png extension)

#removes .png file extension
RewriteEngine On

RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^([^\.]+)$ $1.png [NC,L]
RewriteRule ^([^\.]+)$ $1.jpg [NC,L]
RewriteRule ^([^\.]+)$ $1.jpeg [NC,L]

Answer

Try it like this working for me

RewriteEngine On    
RewriteCond %{REQUEST_FILENAME}.png -f
RewriteRule ^([^\.]+)$ $1.png [NC]
RewriteCond %{REQUEST_FILENAME}.jpg -f
RewriteRule ^([^\.]+)$ $1.jpg [NC]
RewriteCond %{REQUEST_FILENAME}.jpeg -f
RewriteRule ^([^\.]+)$ $1.jpeg [NC,L]
Comments