简体   繁体   English

htaccess-将旧网址重定向到包含旧网址的新网址(即子目录)

[英]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 状况:需要重定向www.example.com/ 小部件的类型 www.example.com/ 控件类/插件型

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. ...产生了500错误...应有的错误,因为目标URL包含原始字符串,因此它会不断处理。

Using one of the several "redirect generators" produces either no effect, or a 500 sitewide. 使用几种“重定向生成器”之一不会产生效果,或在整个站点范围内产生500种效果。

Soo... what's the proper, working syntax for redirecting a URL to a new URL that contains an exact match of the old URL? 那么...将URL重定向到包含与旧URL完全匹配的新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 . 那应该只重定向/widget-type

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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