2011-06-01 94 views

回答

1

將這個代碼在.htaccess文件:

Options +FollowSymlinks -MultiViews 
RewriteEngine on 

RewriteCond %{REQUEST_URI} ^/+id/([^/]*)/type/([^/]*)/url/(http://)?(.*)$ [NC] 
RewriteRule^/api.php?uid=%1&type=%2&url=%3%4 [L,NE] 

這將同時支持/id/1/type/2/url/http://domain2.tld/id/1/type/2/url/domain2.tld的URI。

+0

非常感謝,正在工作:) – Alexander 2011-06-03 07:58:25

0

現在我們開始營業了!創建.htaccess文件,然後將這些行:

RewriteEngine On 
RewriteBase/
RewriteCond %{REQUEST_FILENAME} !-f 
RewriteCond %{REQUEST_FILENAME} !-d 
RewriteRule ^id/(.*)/type/(.*)/url/http:/(.*)$ api.php?uid=$1&type=$2&url=$3 [L] 

注意,這最終會傳遞domain2.tldurl參數 - 你要添加的「http://」回你自己。正如我們在評論中所討論的那樣,您最好使用urlencode的正確格式的網址,但如果這不是一個選項,則會執行此操作。

網上沒有關於mod_rewrite的信息缺失。這裏有一個博客:http://www.htmlist.com/how-to/a-simplemod_rewrite-tutorial/ - 如果您在Google上搜索「mod_rewrite」,則只是衆多搜索結果中的一個。

+0

我已經試過這個,但不工作。在url /我需要使用http://domain.tld之後,這不起作用。 – Alexander 2011-06-01 18:56:41

+0

A)我不明白你的意思是「uset http://domain.tld,這不起作用」,以及B)如果你已經包含了你已經嘗試過的東西,所以我們不會**浪費我們的時間**建議你已經嘗試過的事情。這部分工作中的原則 - 我直接從我自己的網站上運行的htaccss文件中取出。 :)編輯你的問題,幷包括所有相關的細節,包括你已經嘗試過。 – 2011-06-01 18:59:23

+0

我有一個像這樣的鏈接api.php?uid = 1&args = 1&url = http://domain.tld(http://之間沒有空格),我想用^ id /(.*)重寫這個鏈接, /type/(.*)/url/(.*)$最後的語法不起作用,我的PHP沒有得到$ 3。沒有mod_rewrite一切都很好,但模式重寫不工作$ 3(&url = $ 3)。我不知道如何解釋更多。 – Alexander 2011-06-01 19:04:30