如果您在子目录中,则可以使用 mod_rewrite,或者这就是您的其他 static.example.com 将要做的所有事情。
将这样的内容添加到该子目录中的 .htaccess 中。
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteCond %{query_string} ^height=([^&]+)&width=([^&]+)
RewriteRule (.*\.jpg|.*\.png|.*\.gif) controller.php?name=$1&height=%1&width=%2
</IfModule>
编辑:试试上面的。像其他一切一样,未经测试... :)
GET 参数的顺序变得很重要。
test.jpg?height=100&width=120
应该变成
controller.php?name=test.jpg&height=100&width=120
另一种方法是让 apache 将 .jpg 作为该目录的 php 脚本提供服务。只需查看您的 httpd.conf 或 php.conf 并查找 .php。找到该指令,并将其复制到
<Directory>
for .jpg 中。我从来没有真正为单个目录尝试过这个,但最终它会比 mod_rewrite 路由更快。
就像是:
<Files *.jpg>
SetOutputFilter PHP
SetInputFilter PHP
</Files>
AddType application/x-httpd-php .jpg