.htaccess rewrite url - show html file as jpg

大憨熊 提交于 2020-01-03 05:58:11

问题


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?

I tried

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

but without any luck.

Thanks for all answers


回答1:


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.

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

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



来源:https://stackoverflow.com/questions/16512583/htaccess-rewrite-url-show-html-file-as-jpg

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!