重定向到不同的域和URL结构 [英] Redirect to different domain and URL structure

查看:192
本文介绍了重定向到不同的域和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]

这篇关于重定向到不同的域和URL结构的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆