我有位于 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]
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]