URL友好使用htaccess

时间:2014-09-11 10:23:56

标签: apache .htaccess url mod-rewrite

拥有以下网址,但只有第一个使用我的htaccess代码。请帮助解决这个问题。谢谢。

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

输出:http://domain.com/Apple(没关系)

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

输出:http://domain.com/Apple-Board(这不行)

预期输出: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 个答案:

答案 0 :(得分: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]