重定向而不改变 URL

发布于 2024-09-26 01:26:19 字数 232 浏览 0 评论 0原文

我想将域domain1.com完全重定向到domain2.com,但不更改domain1.com URL。 我以为我可以用 .htaccess 做到这一点,但我发现这是不可能的,因为它们位于不同的域,我应该在 .htaccess 规则中使用 http://,所以这将是外部重写而不是内部重写,所以网址将会改变。

还有其他解决办法吗?使用 iframe 是唯一的解决方案吗? 我必须补充一点,我不想更改这 2 个域的 DNS 设置。

i want to redirect domain domain1.com to domain2.com completely but without changing domain1.com URL.
i thought i could do that with .htaccess but i found out that it is not possible because they are to different domains and i should use http:// in .htaccess rule so it would be an external rewriting not an internal rewriting,so the URL will change.

is there any other solution? is using iframe the only solution?
i have to add that i don't want to change DNS setting for these 2 domains.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

凉城凉梦凉人心 2024-10-03 01:26:19

如果两个域都指向同一台服务器,那么您可以将 apache 配置设置为将两个域指向同一文档根目录。

NameVirtualHost *

<VirtualHost *>
ServerName domain1.com
DocumentRoot /www/mysite
</VirtualHost>

<VirtualHost *>
ServerName domain2.com
DocumentRoot /www/mysite
</VirtualHost>

不过,我建议使用domain2.com 重定向(在.htaccess 中使用302 重定向),因为它将改善您的搜索引擎优化,因为这两个网站将被视为一个网站。因此,如果 GoogleBot 发现 domain2.com 作为另一个网站中的链接,它会将其作为 pagerank 添加到 domain1.com。

If both domains point at the same server then you can setup your apache config to point both domains at the same document root.

NameVirtualHost *

<VirtualHost *>
ServerName domain1.com
DocumentRoot /www/mysite
</VirtualHost>

<VirtualHost *>
ServerName domain2.com
DocumentRoot /www/mysite
</VirtualHost>

However, I would recommend domain2.com redirects (with a 302 redirect in the .htaccess) because it will improve your search engine optimisation, as both sites will be considered as one. So if a GoogleBot finds domain2.com as a link in another site, it will add it as a pagerank to domain1.com.

短暂陪伴 2024-10-03 01:26:19

如果它们在同一网络服务器上运行,您可以将domain2设置为domain1的服务器别名。

我以为我曾经读过你可以给 mod rewrite 一个标志,它在内部将请求代理到另一个域,但是我自己从未使用过这个(如果它存在的话),我不能诚实地说我认为它会很棒为了性能..(但也许是..)

但是为什么您希望两个不同的域显示完全相同的网站,而不将主机名更改为您所看到的主要域名。我可以问一下吗?

If they run on the same webserver you could set domain2 as an ServerAlias for domain1.

I thought I once read you could give a flag to mod rewrite that it internally proxies the request to another domain, however I have never used this myself (if it even exists) and I can't honestly say I think it'll be great for performance.. (but maybe it is..)

But why would you want two different domains show the exact same website, without changing the hostname to, what you see as, the primary one. If I might ask?

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文