如果执行的脚本是服务器上的PHP脚本,有没有办法忽略RewriteRule?

I have a rewrite rule intended to route the users to my index.php if they visit my /images/* directory so that I can route this correctly and check user permissions before displaying the image.

However, the issue here is that when I try to display the image to the user, the call to display the image is being picked up by the RewriteRule too.

Is there a way to ignore the RewriteRule if the file executing is PHP/phtml?

My htaccess

RewriteEngine on

RewriteRule (/)?images/(.*)$ /index.php?request=$1 [L,QSA]

RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php?request=$1 [L,QSA]

I'm looking for something like

if the file executing is not a PHP script/being called from the server:
    RewriteRule (/)?images/(.*)$ /index.php?request=$1 [L,QSA]

You can use a RewriteCond to check if current request is not for .php:

RewriteEngine on

RewriteCond %{REQUEST_URI} !\.php$ [NC]
RewriteRule (/)?images/(.+)$ /index.php?request=$1 [L,QSA]

RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php?request=$1 [L,QSA]

You can try below code :-

.htaccess code :-

RewriteRule (/)?images/authorize/(.*)$ /images/$1 [L,QSA]  // Change path or name according to you
RewriteRule (/)?images/(.*)$ /index.php?request=$1 [L,QSA]

PHP code :-

check for user authorization.

if ($user) // Authorized
{
  redirect ('http://project_name/image/authorize/test.jpg'); //// Change path or name according to you
} else {
echo 'Not Authorized';
}

It may help you.

I'm not too proficient in url rewrites. but i think you might want to try using 2 REWRITE_COND directives. one for the checking the IP of requester, and the other for the file types.

this might be useful

"REMOTE_ADDR The IP address of the remote host (see the mod_remoteip module)."

so what i am saying is, maybe you can check the IP and allow the IP of your own webserver(first cond) to access the images(for this you need the second cond). and you should be good to go.