【问题标题】:how to change site path and create subdomain using htaccess如何使用 htaccess 更改站点路径和创建子域
【发布时间】:2013-08-26 18:54:44
【问题描述】:

我有一个 index.php 位于服务器公共根目录的站点。

网址是

 http://example.com

我创建了一个名为“travel”的子文件夹并将整个网站内容移入其中。

使用 .htaccess ,我现在如何将我的网站放在这个地址(带有子域 travel):

http://travel.example.com

【问题讨论】:

    标签: .htaccess subdomain url-redirection


    【解决方案1】:

    为什么是 htaccess 以及为什么不只是这样的 Apache 配置中的 VirtualHost 条目:

    <VirtualHost *:80>
        ServerName www.example.com
        ServerAlias example.com 
        DocumentRoot /www/domain
    </VirtualHost>
    
    <VirtualHost *:80>
        ServerName travel.example.com
        DocumentRoot /www/domain/travel
    </VirtualHost>
    

    编辑基于 .htaccess 的解决方案:

    通过httpd.conf启用mod_rewrite和.htaccess,然后把这段代码放到你.htaccessDOCUMENT_ROOT目录下:

    Options +FollowSymLinks -MultiViews
    # Turn mod_rewrite on
    RewriteEngine On
    RewriteBase /
    
    RewriteCond %{HTTP_HOST} ^travel\.example\.com$ [NC]
    RewriteRule (?!travel/)^(.*)$ travel/$1 [L,NC]
    

    【讨论】:

    • 该网站托管在一个 Paas 中,恐怕我无法访问服务器 conf。
    • travel.example.com目前指向哪里?它是否从服务器公共根目录打开相同的index.php
    猜你喜欢
    • 2010-10-26
    • 1970-01-01
    • 2021-09-01
    • 2013-04-24
    • 2012-03-30
    • 1970-01-01
    • 2018-09-02
    • 2018-07-10
    相关资源
    最近更新 更多