问题
I'm trying to redirect a dynamic URL which is as follows:
http://example.com/manage/billing/invoice/all/viewinvoice.php?id=1541
and I need it to redirect to:
http://example.com/manage/billing/invoice/1541/
I want to do this using .htaccess
I got as far as this but I cannot seem to get it to work:
RewriteCond %{THE_REQUEST} ^[A-Z]{3,9}\ /manage/billing/invoice/all/viewinvoice\.php\?id=([^\ ]*)
RewriteRule ^ /manage/billing/invoice/all/%1 [L,R=301]
Anyone got any suggestions?
回答1:
Add this to your .htaccess
in your web root /
directory
Options +FollowSymLinks -MultiViews
# Turn mod_rewrite on
RewriteEngine On
RewriteBase /
RewriteCond %{THE_REQUEST} ^GET\ /(.*?)/all/viewinvoice\.php\?id=([^&\s]+)&? [NC]
RewriteRule ^ /%1/%2/? [L,R=301]
RewriteRule ^(.*?/invoice)/([^/]+)/?$ /$1/all/viewinvoice.php?id=$2 [NC,QSA,L]
来源:https://stackoverflow.com/questions/18432074/redirecting-a-dynamic-url-to-another-dynamic-url-using-htaccess