2014-09-11 129 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