1

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 Answer 1

0

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]
Sign up to request clarification or add additional context in comments.

3 Comments

This seems to be the right direction, but it also seems to be adding this to the end of the URL: /manage/billing/invoice/1541%20HTTP/1.1/ so I need to remove the %20HTTP/1.1 to get a correctly formatted URL. Any ideas why it is adding this?
@user2715969 Ah, my bad. The bit at the end needs to be ([^&\s]+)&?.
Works a treat. Thanks!

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.