2011-12-01 42 views
1

我想重新格式化我的網址有點短。現在鏈接最終是這樣的:website.com/image?id=name.jpg需要幫助從mod_rewrite中刪除URL的一部分

我想鏈接出來,因爲是m.website.com/name,沒有文件exvola或圖像。在URL中的PHP文件。我想mod_rewrite是這樣做的,所以任何幫助將不勝感激。

回答

0

爲了使這樣的人訪問URL http://m.website.com/name被服務的內容爲http://website.com/image?id=name.jpg,你首先需要檢查主機名m.website.com,再搭配URI的一部分。使用該匹配,您可以代理的請求(使用[P]),或者如果website.comm.website.com都託管在同一臺服務器上,則只需進行簡單的內部重寫。嘗試把這個在你的.htaccess文件在你的文檔根目錄:

RewriteEngine on 
# check the host (NC = no case) 
RewriteCond %{HTTP_HOST} ^m\.website\.com$ [NC] 
# don't rewrite /image 
RewriteCond %{REQUEST_URI} !^/image 
# Match the first non-slash word and rewrite 
RewriteRule ^([^/]+)$ /image?id=$1 [L] 

這將改寫http://m.website.com/name到/image?id=name.jpg,但它不會改寫http://m.website.com/path/name。如果要將路徑(以及其他所有內容)包含在id參數中,請在RewriteRule中將([^ /] +)更改爲(。*)

+0

'R'用於外部重定向!去掉它! – undone

+0

你是對的,不知道我在想什麼。 –

+0

完美的工作,非常感謝你的幫助。 –