JGeer
JGeer

Reputation: 1852

htaccess 301 redirect wildcard

I am looking for a 301 wildcard redirect solution for the following. I changed the following url layout.

https://www.example.com/print-scan

to

https://www.example.com/printing

Now all old pages should be redirecting to the new URL layout, so for example:

https://www.example.com/print-scan/scanners/product1

must go to

https://www.example.com/printing/scanners/product1

How can I achieve that?

Upvotes: 1

Views: 5746

Answers (1)

anubhava
anubhava

Reputation: 785266

You may use this rule as your very first rule:

RewriteEngine On

RewriteRule ^print-scan(/.*)?$ /printing$1 [L,NC,NE,R=301]

Pattern (/.*)? allows you match any of the following URIs:

  • /print-scan (no trailing slash)
  • /print-scan/ (with trailing slash)
  • /print-scan/anything
  • /print-scan/scanners/product1

Upvotes: 4

Related Questions