.htaccess重定向子文件夹

.htaccess重定向子文件夹,.htaccess,mod-rewrite,redirect,.htaccess,Mod Rewrite,Redirect,嗨,我不是一个程序员,我尝试在我的htaccess文件中执行multi-301重定向,基于以下内容: 所以我有很多URL都有相似的命名约定——这里是2个URL的示例 http://www.hollandsbrook.com/garrett-at-gold/ http://www.hollandsbrook.com/garrett-ace-250/ 这些URL需要重定向到: http://www.hollandsbrook.com/garrett-metal-detectors/garrett-

嗨,我不是一个程序员,我尝试在我的htaccess文件中执行multi-301重定向,基于以下内容:

所以我有很多URL都有相似的命名约定——这里是2个URL的示例

http://www.hollandsbrook.com/garrett-at-gold/
http://www.hollandsbrook.com/garrett-ace-250/
这些URL需要重定向到:

http://www.hollandsbrook.com/garrett-metal-detectors/garrett-at-gold/
http://www.hollandsbrook.com/garrett-metal-detectors/garrett-ace-250/
我可以一次重定向一行,但我想使用正则表达式

以下是我到目前为止的想法,但不起作用:

重写规则^garrett-([a-z])/$/garrett金属探测器/$1/[R]

基本上,我需要直接重定向以“garrett-”开头的任何页面,以包括“garrett metal Detector”的文件夹路径


任何想法都将不胜感激。非常感谢您的帮助。

我不是正则表达式方面的专家,但看起来您的注册表可能有点不对劲

尝试:

这是查找任何以“garrett”开头,后跟任何字母/数字/连字符组合的内容


注意:在目标部分使用“garett”会给您一个重定向循环,因此您可能需要选择一个不同的单词,或者将其全部删除…

如果您想要临时重定向,请使用:

RewriteRule ^garrett\-([a-z0-9\-]+)/?$ /garrett-metal-detectors/garrett-$1/ [R=302,L]
RewriteRule ^garrett\-([a-z0-9\-]+)/?$ /garrett-metal-detectors/garrett-$1/ [R=301,L]
如果要永久重定向,请使用:

RewriteRule ^garrett\-([a-z0-9\-]+)/?$ /garrett-metal-detectors/garrett-$1/ [R=302,L]
RewriteRule ^garrett\-([a-z0-9\-]+)/?$ /garrett-metal-detectors/garrett-$1/ [R=301,L]

老兄,你太棒了!我意识到我不想重定向分类页面(garrett metal detectors),所以我对您的代码做了一个小小的编辑:ewriteRule^garrett \-([a-ln-z \-]+)/?$/garrett metal detectors/garrett-$1/[R=301,L]再次感谢!