重定向已重定向的域的URL

时间:2015-02-10 09:12:05

标签: .htaccess redirect

我甚至不知道如何正确地提出这个问题,因为我以前从未见过它。我非常适合编辑名称服务器,创建记录和cnames等,但我不知道这是否可行。

我有一个拥有多个域的客户端,这些域都指向同一个站点。所以说主域名是 www.client-site.com。那么 www.other-domain-1.com www.other-domain-2 .com 只需设置为301重定向即可指向 www.client-site.com

所以一切都很好,直到现在他要求 www.other-domain-1.com/facebook www.other-domain-1.com/linkedin 指向他的Facebook页面或linkedin个人资料,而不是重定向到主域。

301重定向发生在注册商处,我不相信有办法从那里做他想做的事。但我想我可以将其指向Web主机名称服务器并将其作为插件域包含,然后使用.htaccess文件仅执行主机名的301重定向,然后根据需要重定向主机名/路径。

那么这样做的正确方法是什么?有点像...

Redirect 301 http://other-domain-1.com/facebook http://facebook.com/account
Redirect 301 http://other-domain-1.com/linkedin http://linkedin.com/profile
Redirect 301 http://other-domain-1.com http://client-site.com

2 个答案:

答案 0 :(得分:1)

您可以在DOCUMENT_ROOT/.htaccess文件中使用此代码:

RewriteEngine On

# facebook redirect
RewriteCond %{HTTP_HOST} ^(www\.)?other-domain-1\.com$ [NC]
RewriteRule ^facebook/?$ http://facebook.com/account [L,NC,R=302]

# linked-in redirect
RewriteCond %{HTTP_HOST} ^(www\.)?other-domain-1\.com$ [NC]
RewriteRule ^linkedin/?$ http://linkedin.com/profile [L,NC,R=302]

# rest of the redirects
RewriteCond %{HTTP_HOST} ^(www\.)?other-domain-1\.com$ [NC]
RewriteRule ^ http://client-site.com%{REQUEST_URI} [L,NE,R=302]

答案 1 :(得分:0)

因此基于上述anubhava答案在我的服务器上运行的解决方案是

facebook redirect
RewriteCond %{HTTP_HOST} ^(www\.)?other-domain-1\.com$ [NC]
RewriteRule ^facebook/?$ http://facebook.com/account [L,NC,R=302]

然后在完成所有工作后,将R=302更改为R=301以使重定向永久化。