htaccess redirect invoice.php to /client/invoice.php

I am looking at installing Wordpress into my WHMCS website and I would like to make it so any old invoices or support tickets go to the new subfolder.

Current links will look like this

https://www.example.com/viewinvoice.php?id=15515
https://www.example.com/viewticket.php?tid=955170&c=j3122yq7

What should I put in .htaccess so anyone who goes to those links will be redirected to:

https://www.example.com/client/viewinvoice.php?id=15515
https://www.example.com/client/viewticket.php?tid=955170&c=j3122yq7

Answers 1

  • So, you just want to inject a /client subdirectory, for specific URLs, from the document root. You can do this using mod_rewrite, at the top of your .htaccess file (before the WordPress front-controller). For example:

    RewriteRule ^view(invoice|ticket)\.php$ /client/$0 [R=302,L]
    

    This will redirect either /viewinvoice.php or /viewticket.php to /client/viewinvoice.php and /client/viewticket.php respectively. The query string is passed through to the target unaltered.

    The $0 backreference in the substitution refers to the URL-path that matches the entire RewriteRule pattern.

    Note that this is currently a temporary (302) redirect. Change the 302 to 301 if this is intended to be permanent, but only once you have confirmed it works OK (to avoid caching issues). Make sure your browser cache is cleared before testing.


Related Questions