阿帕奇 - 改写图像的PHP文件的.htaccess [英] Apache - rewrite images to php file with .htaccess
问题描述
我在寻找一种方式来从一个文件夹重写所有我的形象的要求到 some.php 文件,而preserving原始图像的URL(或部分路径)。
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 partial path).
因此,
example.com/folder/img/test.jpg
将rewrited的东西像
would be rewrited as something like
example.com/folder/some.php?img=img/test.jpg
(这是最好的办法?)
(is this the best approach?)
我不熟悉到足够多的witrh经常EX pressions,所以我会很心存感激:)
I'm not familiarized enought witrh regular expressions, so I'll be very thankfull :)
注意:我以前尝试了一些解决方案,其中没有工作。另外,我正在的Apache 2.0 在的CentOS 环境。
note : I've tried some solutions before, none of them worked. ALso, I'm running Apache 2.0 under CentOS environment.
推荐答案
到的httpd.conf
启用了mod_rewrite和.htaccess,然后把这个code在< $ C C>的.htaccess $ DOCUMENT_ROOT
目录下:
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]
确认:
- 的.htaccess启用
- mod_rewrite的启用
- 您的网址是
http://example.com/folder/img/test.jpg
这篇关于阿帕奇 - 改写图像的PHP文件的.htaccess的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!