Apache - rewrite images to php file with .htaccess

后端 未结 3 2078
慢半拍i
慢半拍i 2020-12-10 21:14

I\'m looking for a way to rewrite all my image requests from one folder into some.php file, while preserving the original image url (or par

3条回答
  •  暖寄归人
    2020-12-10 22:01

    Enable mod_rewrite and .htaccess through httpd.conf and then put this code in your .htaccess under DOCUMENT_ROOT directory:

    Options +FollowSymLinks -MultiViews
    # Turn mod_rewrite on
    RewriteEngine On
    RewriteBase /
    
    RewriteRule ^(folder)/(img/[^.]+\.jpg)$ $1/some.php?img=$2 [L,QSA,NC]
    

    Make sure:

    • .htaccess is enabled
    • mod_rewrite is enabled
    • Your URL is http://example.com/folder/img/test.jpg

提交回复
热议问题