简体   繁体   English

将子域重定向到另一个域的文件夹中

[英]Redirect subdomain into a folder of another domain

I'm trying to redirect one subdomain (a wordpress.com domain) into a folder of another domain. 我正在尝试将一个子域(一个wordpress.com域)重定向到另一个域的文件夹中。 Example: 例:

blog.domain.com to anotherdomain.com/blog

I know that is possible by using .htacces files, but i dont have a hosting service on my first domain. 我知道可以通过使用.htacces文件来实现,但我的第一个域上没有托管服务。

Is it possible to do it by using DNS? 是否可以通过使用DNS来做到这一点?

I have tried by creating some A and CNAME registrations but I cant find a way to do it: Can I have a ip for a specific folder of my second domain? 我已经尝试通过创建一些A和CNAME注册来进行尝试,但是我找不到解决方法:我可以为第二个域的特定文件夹使用ip吗?

Thanks :) 谢谢 :)

I attempted to do a comment but it's too much. 我试图发表评论,但太多了。 You can do this if you own both domains. 如果您同时拥有两个域,则可以执行此操作。 If you don't have hosting on the first domain but you do on the other domain , then you can add the main domain as an ServerAlias on the other server. 如果您没有在第一个域上托管,但是在other domain上托管,则可以将主域添加为另一台服务器上的ServerAlias

Either through your control panel or your vhost config do the following. 通过控制面板或vhost配置执行以下操作。

  1. Add an A record for blog.domain.com in DNS pointing to the IP address of the other domain with the hosting account. 在DNS中为blog.domain.com添加A记录,以指向具有托管帐户的另一个域的IP地址。
  2. In the configuration of the web server with the hosting add a ServerAlias of blog.domain.com to the anotherdomain.com vhost config. 在具有托管功能的Web服务器的配置中,将blog.domain.comServerAlias添加到anotherdomain.com vhost配置。
  3. in the root of the anotherdomain.com put this code inside your .htaccess file. anotherdomain.com的根目录中,将此代码放入您的.htaccess文件中。

If you want it to actually redirect then you can do this 如果您希望它实际重定向,则可以执行此操作

RewriteEngine on
RewriteCond %{HTTP_HOST} ^blog\.domain\.com [NC]
RewriteRule ^(.*)$ http://anotherdomain.com/blog/$1 [R=301,L]

If you don't want it to redirect and keep blog.domain.com in the address bar then, you can do this. 如果您不希望它重定向并在地址栏中保留blog.domain.com,则可以执行此操作。

RewriteEngine on
RewriteCond %{HTTP_HOST} ^blog\.domain\.com [NC]
RewriteRule ^(.*)$ /blog/$1 [L]

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

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