如何使用的.htaccess重写从图像请求到PHP脚本?

编程入门 行业动态 更新时间:2024-10-17 13:30:21
本文介绍了如何使用的.htaccess重写从图像请求到PHP脚本?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

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

我想要的形式的HTTP请求的://sb1.dev.$c$canywhere/~a70097sb/hc/onlinestatus/ {样式} / {IGN}巴纽来改写为sb1.dev.$c$canywhere/~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 sb1.dev.codeanywhere/~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 sb1.dev.codeanywhere/~a70097sb/hc/onlinestatus/{style}/{ign}.png to be rewritten to sb1.dev.codeanywhere/~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脚本?

本文发布于:2023-11-01 12:59:33,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1549400.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:重写   如何使用   脚本   图像   htaccess

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!