简体   繁体   中英

.htaccess redirect rule to remove specific part from url

I have to do 301 redirection for all my url's something from

http://www.example.com.au/website-blog/item/121-itemName

to

http://www.example.com.au/website-blog/itemName

Need to remove part item/(itemId)- from all urls.

I have tried

RewriteRule ^item/[\d]+-(.*)$ /$1 [L,R=301,QSA].

Any help will be appreciated.

Thanks.

Capture the item name using (.+) and substitute accordingly. Place the following rule in /.htaccess :

RewriteRule ^website-blog/item/\d+-(.+) /website-blog/$1 [R,L]

Note:

  • Change R to R=301 after testing
  • The QSA flag is not required in this case

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