简体   繁体   中英

Htaccess - redirect old URL to new that CONTAINS old URL (i.e. sub-directory)

Situation: need to redirect www.example.com/ widget-type to www.example.com/ widget-category/widget-type

Problem: using this:

RewriteRule ^.*(widget-type).*$ https://example.com/widget-category/widget-type/ [L,NC,R=301]

...generates a 500 error... as it should, since the destination URL contains the original string, so it just processes endlessly.

Using one of the several "redirect generators" produces either no effect, or a 500 sitewide.

Soo... what's the proper, working syntax for redirecting a URL to a new URL that contains an exact match of the old URL?

Your rule can be a lot simpler:

RewriteRule ^(widget-type)$ /widget-category/$1 [L,NC,R=301]

That should only redirect for /widget-type .

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