简体   繁体   English

如何将域和任何子目录重定向到新域?

[英]How to redirect a domain AND any subdirectory to a new domain?

So I'm building a new site and everything at the old site is going to be scrapped - including the domain structure, and domain name. 因此,我正在建立一个新站点,旧站点中的所有内容都将被废弃-包括域结构和域名。 I currently have a redirect rule in my .htaccess setup to redirect http://jagdesignideas.com to http://jag.is as such: 我目前在.htaccess设置中有一个重定向规则,以将http://jagdesignideas.com重定向到http://jag.is ,如下所示:

RewriteCond %{HTTP_HOST} ^(www.)?jagdesignideas.com
RewriteRule ^(/)?$ "http://jag.is" [R=301,L]

But the trouble is if a user follows a link from elsewhere on the intarwebz to http://jagdesignideas.com/about , for example, that does not redirect to http://jag.is as I would like. 但是麻烦是,如果用户从intarwebz上的其他地方访问了http://jagdesignideas.com/about的链接,例如,该链接没有重定向到http://jag.is Instead it brings up the 404 page from the jagdesignideas.com domain. 而是从jagdesignideas.com域中显示404页面。

How to I get all substrings of jagdesignideas.com domain to endup at the new redirect? 如何获取jagdesignideas.com域的所有子字符串以新的重定向方式结束?

EDIT: To be clear, I'm not trying to match pages on the old site to the new site, only do a mass redirect of jagdesignideas.com and anything there just to point at the jag.is domain. 编辑:明确地说,我不是在尝试将旧站点上的页面与新站点匹配,仅对jagdesignideas.com和其中的任何内容进行大规模重定向,仅指向jag.is域。

The isse us what you are matching in your RewriteRule: ^(/)?$ matches the root slash or nothing, which means you are only rewriting calls to your domain root. 这就是我们在RewriteRule中匹配的内容: ^(/)?$匹配根斜杠或什么都不匹配,这意味着您只在重写对域根的调用。 You need to capture all path components instead, using ^.*$ , which matches anything after the domain root, or nothing. 您需要使用^.*$捕获所有路径组件,它匹配域根之后的任何内容,或不匹配任何内容。 This will redirect any call to your old domain, with or without a path, to the root of your new domain: 这会将所有调用重定向到您的旧域(有路径或无路径)到新域的根:

RewriteCond %{HTTP_HOST} ^(www\.)?jagdesignideas\.com [NC]
RewriteRule ^.*$ http://jag.is [R=301,L]

If you want to redirect your path structure to an identical one on your new server, this will do the trick: 如果您要将路径结构重定向到新服务器上的相同结构,则可以做到这一点:

RewriteRule ^.*$ http://jag.is/$0 [R=301,L]

Starting from there, you can basically do any kind of redirect to map old to new path structures – see the Apache Module mod_rewrite reference. 从那里开始,您基本上可以进行任何重定向,以将旧路径映射到新路径结构–请参阅Apache Module mod_rewrite参考。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM