简体   繁体   English

使用.htaccess将子域重定向到文件夹

[英]Redirect sub-domain to a folder using .htaccess

I know this question has been asked many times on SO, but My problem is different and I'm not able to find the solution. 我知道这个问题在SO上已经问过很多遍了,但是我的问题有所不同,我找不到解决方案。

I've a Domain name( https://mydomainname.com ) registered from GoDaddy and the site is hosted on AWS EC2. 我从GoDaddy注册了一个域名( https://mydomainname.com ),并且该网站托管在AWS EC2上。 This site has a blog which is hosted on Azure with sub domain ( https://blog.domainname.com ). 该站点有一个博客,该博客托管在具有子域( https://blog.domainname.com )的Azure上。

The thing is, main site is on Amazon EC2 which is developed in Symfony and the Blog is on Azure developed in Wordpress. 事实是,主站点位于Symfony开发的Amazon EC2上,博客位于Wordpress开发的Azure上。 Now is there any way we can point sub-domain to the sub folder using .htaccess. 现在有什么方法可以使用.htaccess将子域指向子文件夹。 ( https://domainname.com/blog ) https://domainname.com/blog

I think without transferring the files on single host it's not possible, then what is the work around to get it done in Symfony framework. 我认为,如果无法在单个主机上传输文件,那是不可能的,那么如何在Symfony框架中完成该工作呢?

You will have to create redirect rule at your Azure hosting. 您将必须在Azure托管处创建重定向规则。

In the root of the blog.domainname.com website, create a file named Web.config with contents as this: blog.domainname.com网站的根目录中,创建一个名为Web.config的文件,其内容如下:

<?xml version="1.0" encoding="utf-8" ?>
<configuration>
    <system.webServer>
        <rewrite>
            <rules>
                <rule name="Redirect blog domain to main domain" stopProcessing="true">
                    <match url=".*" />
                    <conditions>
                        <add input="{HTTP_HOST}" pattern="^blog\.domainname\.com$" />
                    </conditions>
                    <action type="Redirect" url="http://domainname.com/blog/{R:0}" redirectType="Permanent" />
                </rule>              
            </rules>
        </rewrite>
    </system.webServer>
</configuration>

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

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