2011-06-14 87 views
0

我目前有我自己的URL縮短服務。

我怎麼會去寫.htaccess文件,這樣,如果你去http://www.xxxxx.com/shorturl它會處理shorturl爲縮短的URL(而不是目錄),並把它傳遞到decoder.php文件作爲$_GET變量?

回答

6

請在服務器的Web根目錄下的.htaccess文件中嘗試以下操作,它是mod_rewrite的相當標準用法。如果它已經存在與其他一些Rewrite規則,只需將該塊添加到.htaccess文件末尾,而不需要RewriteEngine On位。

<IfModule mod_rewrite.c> 
    # Turn on the rewrite engine 
    RewriteEngine On 

    # If the page doesn't really exist, run it through decoder.php 
    RewriteCond %{REQUEST_FILENAME} !-f 
    RewriteCond %{REQUEST_FILENAME} !-d 
    RewriteRule /?([A-Za-z0-9_-]+)/?$ decoder.php?id=$1 [QSA,L] 
</IfModule> 
+0

hmph ...沒有運氣。讓我們只是說,縮短的URL是http://www.xxxx.com/hEkr 它會通過http://www.xxxx.com/decoder.php?id=hEkr – Jason 2011-06-14 21:59:27

+0

@Jason:是的,這是正確的。您需要將GET參數名稱更改爲您的'decoder.php'所期待的內容。 – Marcel 2011-06-14 22:03:31

+0

謝謝,我欣賞它! – Jason 2011-06-14 23:05:02