2013-06-26 45 views
2

試圖重寫具有多個參數的頁面的URL,並且其中一個參數包含多個單詞(在提交時用空格分隔)。用多字字符串(帶mod_rewrite)重寫包含多個參數的URL

這將是URL:www.ABCD.com/store/itemsDescr.php?categ=headbands & ID = 123 &名=棕色%20with%20black

我希望URL顯示像這樣: www.ABCD.com/store/headbands/123/brown-with-black

我想這一點,但沒有奏效:

RewriteCond %{QUERY_STRING} ^categ=([^&]+) [NC,OR] 
RewriteCond %{QUERY_STRING} &categ=([^&]+) [NC] 
RewriteRule ^store/itemsDescr\.php$ $0/%1 

RewriteCond %{QUERY_STRING} ^id=([^&]+) [NC,OR] 
RewriteCond %{QUERY_STRING} &id=([^&]+) [NC] 
RewriteRule ^store/itemsDescr\.php/[^/]+$ $0/%1 

RewriteCond %{QUERY_STRING} ^name=([^&]+) [NC,OR] 
RewriteCond %{QUERY_STRING} &name=([^&]+) [NC] 
RewriteRule ^store/itemsDescr\.php/([^/]+/[^/]+)$ http://www.ABCD.com/store/$1/%1/? [L,QSA,NC] 

任何幫助將是非常appre ciated!

注意:這個規則我想實現之前,我已經有另一頁的其他規則,在情況下,它可以產生衝突:

RewriteCond %{THE_REQUEST} ^[A-Z]{3,}\s/+(store)/index\.php\?categ=([^\s]+) [NC] 
RewriteRule^/%1/%2? [R=301,L] 

RewriteCond %{REQUEST_FILENAME} !-f  
RewriteRule ^store/(.+?)/?$ /store/index.php?categ=$1 [L,QSA,NC] 
+0

你是什麼意思:'但是我不想重定向。 – anubhava

+0

這實際上是一個錯字。刪除。我只是想讓網址看起來更加SEO友好... – samyb8

+0

好吧我會採取刺。 (這是多一點參與) – anubhava

回答

1

啓用mod_rewrite的,並通過httpd.conf的.htaccess,然後把這個代碼在你的.htaccessDOCUMENT_ROOT目錄下:

Options +FollowSymLinks -MultiViews 
# Turn mod_rewrite on 
RewriteEngine On 
RewriteBase/

RewriteCond %{QUERY_STRING} ^categ=([^&]+)&id=([^&]+)&name=([^&]+)$ [NC] 
RewriteRule ^(store)/itemsDescr\.php$ /$1/%1/%2/%3? [R=302,L,NC,NE] 

RewriteRule ^(store)/([^\s]+)\s([^\s]+)$ /$1/$2-$3 [R=302,L,NC] 

RewriteRule ^(store)/([^\s]+)\s(.+)$ /$1/$2-$3 [L,NC] 

RewriteCond %{REQUEST_FILENAME} !-f 
RewriteRule ^(store)/([^/]+)/([^/]+)/ /$1/itemsDescr.php?categ=$2&id=$3 [L,QSA,NC,NE] 
+0

毫米......它不再加載預期的頁面,也沒有將URL改爲漂亮的頁面。 – samyb8

+0

它是一個經過測試的解決方案。你試過這個網址:http://www.ABCD.com/store/itemsDescr.php?categ = headbands&id = 123&name = brown%20with%20black'還是別的什麼? – anubhava

+0

是的,這是網址。它所做的是:它保留了原始的醜陋URL,並加載了「www.ABCD.com/store /'而不是'itemsDescr.php」頁面。一個 – samyb8