.htaccess重定向子文件夹

use*_*876 3 .htaccess mod-rewrite redirect

嗨,我不是任何想象力的程序员,我试图根据以下内容在我的htaccess文件中进行多301重定向:

所以我有大量的网址都有类似的命名约定 - 这里是2的样本.

http://www.hollandsbrook.com/garrett-at-gold/
http://www.hollandsbrook.com/garrett-ace-250/
Run Code Online (Sandbox Code Playgroud)

这些网址需要重定向到:

http://www.hollandsbrook.com/garrett-metal-detectors/garrett-at-gold/
http://www.hollandsbrook.com/garrett-metal-detectors/garrett-ace-250/
Run Code Online (Sandbox Code Playgroud)

我可以一次重定向它们一行,但我想使用正则表达式.

这是我到目前为止所想的但不起作用:

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

基本上我需要重定向任何以"garrett-"开头的根页面,以包含"garrett-metal-detectors"的文件夹路径.

任何想法都会受到很多赞赏.非常感谢您的帮助.

Boo*_*eus 6

如果你想要临时重定向使用:

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

如果你想永久重定向使用:

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

  • 背心怎么回答? (5认同)