如何使用的.htaccess重写从图像请求到PHP脚本? [英] How to use .htaccess to rewrite requests from image to PHP script?

查看:222
本文介绍了如何使用的.htaccess重写从图像请求到PHP脚本?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有位于 HTTP PHP脚本://sb1.dev.$c$canywhere.net/~a70097sb/hc/onlinestatus/image.php 要求两个 GET 变量: IGN 风格。我的的.htaccess 文件在同一目录 image.php

我想要的形式的HTTP请求的://sb1.dev.$c$canywhere.net/~a70097sb/hc/onlinestatus/ {样式} / {IGN}巴纽来改写为<$c$c>http://sb1.dev.$c$canywhere.net/~a70097sb/hc/onlinestatus/image.php?style={style}&ign={ign}.如何做到这一点,因为我有mod_rewrite的没有经验,没有能够得到它使用任何我发现在谷歌的辅导工作。

试过,但它没有工作,我只是得到一个404页面:

 选项+了FollowSymLinks -MultiViews
RewriteEngine叙述上

重写规则^([^] *)/([^] *)\ PNG $ image.php风格= $ 1安培;?IGN = $ 2 [L,NC]
 

解决方案

你是在正确的轨道。捕捉模式([^ /] +)匹配一切直到下一个 / ,所以你需要两个那些。

  RewriteEngine叙述上
重写规则^([^ /] +)/([^ /] +)\ PNG $ image.php风格= $ 1安培;?IGN = $ 2 [L,NC]
 

I have a PHP script located at http://sb1.dev.codeanywhere.net/~a70097sb/hc/onlinestatus/image.php that requires two GET variables: ign and style. My .htaccess file is in the same directory as image.php.

I want requests of the form http://sb1.dev.codeanywhere.net/~a70097sb/hc/onlinestatus/{style}/{ign}.png to be rewritten to http://sb1.dev.codeanywhere.net/~a70097sb/hc/onlinestatus/image.php?style={style}&ign={ign}. How do I do this, as I have no experience with mod_rewrite, and wasn't able to get it to work using any of the tutorials I found on Google.

Tried this but it didn't work, I just get a 404 page:

Options +FollowSymlinks -MultiViews
RewriteEngine on

RewriteRule ^([^.]*)/([^.]*)\.png$ image.php?style=$1&ign=$2 [L,NC]

解决方案

You're on the right track. The capture pattern ([^/]+) matches everything up to the next /, so you'll need two of those.

RewriteEngine On
RewriteRule ^([^/]+)/([^/]+)\.png$ image.php?style=$1&ign=$2 [L,NC]

这篇关于如何使用的.htaccess重写从图像请求到PHP脚本?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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