嗨,我不是一个想像力强的程序员,而是根据以下内容尝试在我的htaccess文件中执行多301重定向:

因此,我有大量的网址都具有类似的命名约定-这是2个示例。

http://www.hollandsbrook.com/garrett-at-gold/
http://www.hollandsbrook.com/garrett-ace-250/


这些网址需要重定向到:

http://www.hollandsbrook.com/garrett-metal-detectors/garrett-at-gold/
http://www.hollandsbrook.com/garrett-metal-detectors/garrett-ace-250/


我可以一次将它们重定向1行,但是我想使用regex。

到目前为止,这是我一直在想的但没有起作用的事情:

RewriteRule ^ garrett-([a-z])/ $ / garrett-metal-detectors / $ 1 / [R]

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

任何想法将不胜感激。在此先感谢您的帮助。

最佳答案

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

如果要永久重定向使用:

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

10-08 08:30