2014-09-11 159 views
0

有以下網址,但只有第一個與我的htaccess代碼一起工作。請幫助解決這個問題。謝謝。URL友好使用htaccess

URL 1:http://domain.com/index.php?id=Apple

輸出:http://domain.com/Apple(這是確定)

URL 2:http://domain.com/index.php?id=Apple-Board&jid=Chief-Accountant

輸出:http://domain.com/Apple-Board(這不是OK)

預期輸出:http://domain.com/Apple-Board/Chief-Accountant

Options -Multiviews 
RewriteEngine on 

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

RewriteCond %{REQUEST_FILENAME} !-d 
RewriteCond %{REQUEST_FILENAME} !-f 
RewriteCond %{REQUEST_FILENAME} !-l 
RewriteRule ^([^/]+)/?$ index.php?id=$1 [B,L] 
RewriteRule /id/(.*)/jobid/(.*)/ index.php?id=$1&jid=$2 

回答

1

您可以使用:

Options -Multiviews 
RewriteEngine on 

RewriteCond %{THE_REQUEST} \s/+index\.php\?id=([^\s&]+)&jid=([^\s&]+) [NC] 
RewriteRule^/%1/%2? [R=302,L] 

RewriteCond %{THE_REQUEST} \s/+index\.php\?id=([^\s&]+) [NC] 
RewriteRule^/%1? [R=302,L] 

RewriteCond %{REQUEST_FILENAME} -d [OR] 
RewriteCond %{REQUEST_FILENAME} -f [OR] 
RewriteCond %{REQUEST_FILENAME} -l 
RewriteRule^- [L] 

RewriteRule ^([^/]+)/?$ index.php?id=$1 [QSA,L] 

RewriteRule ^([^/]+)/([^/]+)/?$ index.php?id=$1&jid=$2 [L,QSA] 
+0

嗨anubhava,感謝您的快速回復。但它仍然不起作用。 (URL 2:http://domain.com/index.php?id=Apple-Board&jid=Chief-Accountant 輸出:http://domain.com/Apple-Board(這不正確) 預期輸出:http://domain.com/Apple-Board/Chief-Accountant) – Antony 2014-09-11 10:40:07

+0

立即嘗試更新的規則。 – anubhava 2014-09-11 10:42:32

+1

Thaks很多anubhava。我接近輸出,需要在php代碼上進行一些修復。再次感謝。 – Antony 2014-09-11 10:47:39