Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
684 views
in Technique[技术] by (71.8m points)

.htaccess - How to redirect all requests to a file, except images using Apache?

I have an .htaccess file with the following contents:

Options +FollowSymLinks +ExecCGI

<IfModule mod_rewrite.c>
  RewriteEngine On
  RewriteRule ^(.*)$ entryPoint.php [QSA]
</IfModule>

With this, I want all requests to be redirected to the file entryPoint.php so that it can examine them:

  • If there is no extension, is must be a module
  • If there's a .php, it's a hacking
  • If it's a .png, then it's a "safe" call.

    In case of images, I used to output headers, and file_get_contents() their content. I figured out it's a bit slower than leaving a direct read.

My question is:

How to prevent this .htaccess from calling entryPoint.php if there are references for images?

Extra feedback on the code I already have is greatly appreciated!

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

As I understand you want to process all non-images threw your php file. Right?

If so, then here is what you need:

Options +FollowSymLinks +ExecCGI

<IfModule mod_rewrite.c>

RewriteEngine On
RewriteCond %{REQUEST_URI}  !(.png|.jpg|.gif|.jpeg|.bmp)$
RewriteRule (.*)  entryPoint.php [QSA]

</IfModule>

Remember to add to delete any image extension you want! If I misunderstood,Please tell me to correct my answer!


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...