2012-08-25 134 views
0

我想知道如何通過網址傳遞幾個(兩個)值作爲一個乾淨的網址。 我以前做過乾淨的網址,但從來沒有多個值,它似乎沒有工作。多個乾淨的網址變量

這是URL看起來像現在:

http://example.com/?user=Username&page=1 

這是我希望它看起來像

http://example.com/user/Username/page/1 

我試過,我已經看到了這裏其他的答案,但他們沒有爲這筆交易工作。

RewriteEngine On 
# Don't match real existing files so CSS, scripts, images aren't rewritten 
# RewriteCond %{REQUEST_FILENAME} !-f 
# RewriteCond %{REQUEST_FILENAME} !-d 

# Match the first two groups before/and send them to the query string 
RewriteRule ^([^/]+)/([^/]+) index.php?user=$1&page=$2 [L] 

謝謝。 :) 我使用的方式。 :)

此外,我仍然可以使用$ _GET與此?我是這麼認爲的,但我也別的地方它說你不能...:d

回答

3

你錯過了幾場比賽,嘗試:

RewriteEngine On 
# Don't match real existing files so CSS, scripts, images aren't rewritten 
RewriteCond %{REQUEST_FILENAME} !-f 
RewriteCond %{REQUEST_FILENAME} !-d 

RewriteRule ^([^/]+)/([^/]+)/([^/]+)/([^/]+) index.php?$1=$2&$3=$4 [L] 

這將需要一個網址,如:

http://example.com/a/b/c/d 

到URI:

/index.php?a=b&c=d 

是否仍然可以使用$ _用這個?我是這麼想的,但我也在其他地方說過你不能。

在上例中,當您看到$_GET['a']時,您會得到b

+0

非常感謝!我試圖測試這一點,但不幸的是,我使用000webhost作爲一個免費的主機,由於某種原因它的htaccess搞亂了:/ – transparent

+0

我得到它的工作。感謝您的幫助! :) – transparent