重定向到不同的域和URL结构

问题描述:

我需要将网站的一部分永久重定向到其他域和URL结构。

I need to permanently redirect part of a website to a different domain and URL structure.

所有匹配项:
example.com/year/month / day / page-name /

www.example.com/year/month/day/page-name /

Everything that matches: example.com/year/month/day/page-name/ and www.example.com/year/month/day/page-name/

需要重定向到:
www.sample.com/sub/sub2/year/month/page-name /

Needs to redirect to: www.sample.com/sub/sub2/year/month/page-name/

例如:
example.com/ 2013/11/09 / a-great-page /

For example: example.com/2013/11/09/a-great-page/

应永久指向:
www.sample.com/sub/sub2/2013/11/ a-great-page /

should permanently point to: www.sample.com/sub/sub2/2013/11/a-great-page/

但我不想重定向网站上的任何其他页面:
example.com/a-random-page
不应重定向到任何地方。

But I don't want to redirect any other pages on the site: example.com/a-random-page Shouldn't redirect anywhere.

我的htaccess排行和正则表达式技能有点生锈,因此任何帮助将不胜感激!

My htaccess chops and regex skills are a little rusty, so any help would be greatly appreciated!

通过以下方式启用 mod_rewrite .htaccess httpd.conf (如果尚未启用),然后将此代码放在 DOCUMENT_ROOT / .htaccess 文件中:

Enable mod_rewrite and .htaccess through httpd.conf (if not already enabled) and then put this code in your DOCUMENT_ROOT/.htaccess file:

RewriteEngine On

RewriteCond %{HTTP_HOST} ^(www\.)?example\.com$ [NC]
RewriteCond %{SERVER_PORT}s ^(443(s)|\d+s)$
RewriteRule ^([0-9]{4}/[0-9]{2}/[0-9]{2}/[^/]+/?)$ http%2://sample.com/sub/sub2/$1 [L,QSA,R=301]