2012-07-10 34 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>