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

2023-09-02 11:26:02 作者:来,给爷笑一个

我有位于 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}巴纽来改写为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]
 

linux下的php网站放到Windows服务器IIS下.htaccess文件伪静态规则转换

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]