开发者

Dealing with broken images in the context of friendly URLs

开发者 https://www.devze.com 2023-04-12 06:26 出处:网络
I use the following .htaccess code to enable friendly URLs in a website. RewriteEngine on RewriteCond %{REQUEST_FILENA开发者_如何学PythonME} !-f

I use the following .htaccess code to enable friendly URLs in a website.

RewriteEngine on
RewriteCond %{REQUEST_FILENA开发者_如何学PythonME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php?$1 [L]

It works as it's supposed to but there's something that bugs me. When, let's say, I request a page that has a <img src="sth.png" /> in it and sth.png does not exist on the server, the .htaccess code will instruct the server to make a request to index.php?sth.png, which would result in a completely unnecessary load of the whole framework of the website.

What can I do to prevent that?


Adding this RewriteCond:

RewriteCond %{REQUEST_FILENAME} !\.png$

should exclude PNG files from being subjected to the Rewrite rules.

But as said in the comment, I would consider handling 404s within index.php regardless of their type - they shouldn't happen so often that loading the PHP file becomes a performance issue anyway.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号