简体   繁体   中英

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?

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM