dongmeixi5311 2014-01-21 11:57
浏览 38
已采纳

基于域的静默重定向

I've set up my own server.

Let's say my main server folder is /home/www and I've set the nameservers so that all domains point to this location.

Now, here's what I want to do :

  • Have each domain's files in a separate subfolder
  • Based on the domain requested, silently redirect to the appropriate subfolder

E.g.

  • if we need somedomain.com or www.somedomain.com or www.somedomain.com/anything/ (or any such variation for that matter) redirect the request from /home/www/ to /home/www/somedomain.com/

How can this be done?


And here's what I've tried (but given that .htaccess is definitely ... not my thing, it'll most likely be close to non-sensical...) :

RewriteEngine On
RewriteBase /

RewriteCond %{HTTP_HOST} ^(www.)?somedomain.com$ [NC]
RewriteRule ^(/)?$ somedomain.com [L]
  • 写回答

2条回答 默认 最新

  • douwojiao5919 2014-01-21 12:01
    关注

    There are two possible choices. you can create Virtual Host for each domain and set virtual document root. Or You can use rewrite rule.

    From apache Virtual host documentation:

    # Listen for virtual host requests on all IP addresses
    NameVirtualHost *:80
    
    <VirtualHost *:80>
    DocumentRoot /www/www.example1.com
    ServerName www.example1.com
    
    # Other directives here
    
    </VirtualHost>
    
    <VirtualHost *:80>
    DocumentRoot /www/www.example2.org
    ServerName www.example2.org
    
    # Other directives here
    
    </VirtualHost> 
    

    You can find out more in http://httpd.apache.org/docs/2.2/vhosts/examples.html

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥30 这是哪个作者做的宝宝起名网站
  • ¥60 版本过低apk如何修改可以兼容新的安卓系统
  • ¥25 由IPR导致的DRIVER_POWER_STATE_FAILURE蓝屏
  • ¥50 有数据,怎么建立模型求影响全要素生产率的因素
  • ¥50 有数据,怎么用matlab求全要素生产率
  • ¥15 TI的insta-spin例程
  • ¥15 完成下列问题完成下列问题
  • ¥15 C#算法问题, 不知道怎么处理这个数据的转换
  • ¥15 YoloV5 第三方库的版本对照问题
  • ¥15 请完成下列相关问题!