的.htaccess重写URL - 显示HTML文件为JPG [英] .htaccess rewrite url - show html file as jpg

查看:146
本文介绍了的.htaccess重写URL - 显示HTML文件为JPG的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有image.html,我想它在浏览器image.jpg文件显示,由于显示图像时,也有一些操作,无法之前或之后完成。用的.htaccess和URL重写它甚至有可能?

I have image.html and I want It to be shown in browser as image.jpg, because there are some operations when showing picture, that can't be done before or after. Is it even possible with .htaccess and url rewriting?

我试过

RewriteEngine On
RewriteBase /    
RewriteRule ^image\.html$ image.jpg

但没有任何运气。

but without any luck.

感谢所有的答案

推荐答案

首先,你需要让我们说的PHP脚本。说它 image.php 。在此之后,使用GET参数处理图像名称。让我们把它叫做名称。打电话给你需要的图片 image.php?NAME =异基因

First of all, you'll need let's say a PHP script. Call it image.php. After that, use a GET parameter to handle the image name. Let's call it name. To call a picture you need image.php?name=allo.

现在。在PHP脚本中,你需要在它的图像,JPEG头指定。需要。之后,只需打印页面中的图片。

Now. In the PHP script, you need to specify in the header it's an image, JPEG. Required. After that, just "print" the picture within the page.

所有你需要的之后是重写规则。

All you need after is Rewrite rule.

RewriteEngine On
RewriteBase /    
RewriteRule ^image\.php?name=(.*)$ /images_jpeg/$1

标题是非常重要的。这就是为什么它不与一个HTML文件工作。

The header is really important. This is why it doesn't work with an HTML file.

这篇关于的.htaccess重写URL - 显示HTML文件为JPG的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆