当前位置: 动力学知识库 > 问答 > 编程问答 >

apache - URL Friendly using htaccess

问题描述:

Having the below urls, but only the first one works with my htaccess code. Please help to fix this for both url at time. Thank you.

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

Output : http://domain.com/Apple (This is ok)

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

Output : http://domain.com/Apple-Board (This is not ok)

Expected Output : 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

网友答案:

You can use:

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]
分享给朋友:
您可能感兴趣的文章:
随机阅读: