2012-07-10 65 views
1

我有一个PHP脚本位于http://sb1.dev.codeanywhere.net/~a70097sb/hc/onlinestatus/image.php需要两个GET变量:ignstyle。我的.htaccess文件与image.php位于同一个目录中。如何使用.htaccess将图像重写为PHP脚本?

我希望将表格http://sb1.dev.codeanywhere.net/~a70097sb/hc/onlinestatus/{style}/{ign}.png的请求重写为http://sb1.dev.codeanywhere.net/~a70097sb/hc/onlinestatus/image.php?style={style}&ign={ign}。我该怎么做,因为我没有使用mod_rewrite的经验,并且无法使用我在Google上找到的任何教程来运行它。

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

Options +FollowSymlinks -MultiViews 
RewriteEngine on 

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

回答

3

你在正确的轨道上。捕获模式([^/]+)匹配下一个/,因此您需要其中两个。

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

两个答案似乎都没有工作。看到我更新的问题,我包括了实际的网站,因为我认为它可能与子域有关。我在这些路径的开头添加了〜〜a70097sb /',但它仍然不起作用。 – 2012-07-10 02:07:18

+0

@DC_看到我的更新 - 对不起,我错过了关于您的.htaccess在'image.php'目录中的部分。 – 2012-07-10 02:09:47

+0

仍然不工作:http://sb1.dev.codeanywhere.net/~a70097sb/hc/onlinestatus/test/test.png – 2012-07-10 02:12:17

0

尝试类似的东西:

<IfModule mod_rewrite.c> 
    RewriteEngine On 
    RewriteCond %{HTTP_HOST} ^www\.mysite\.com [NC] 
    RewriteRule ^hc\/onlinestatus\/(.*)\/(.*)\.png /hc/onlinestatus/image.php?style=$1&ign=$2 [NC,L] 
</IfModule>