Redirecting a dynamic URL to another dynamic URL using htaccess

这一生的挚爱 提交于 2021-02-10 18:47:52

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!