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]

图片转代码服务由CSDN问答提供 功能建议

我已经设置了自己的服务器。

让我们说我的主要 服务器文件夹是 / home / www ,我设置了名称服务器,以便所有域都指向此位置。

现在,这就是我想要的 要执行的操作:

  • 将每个域的文件放在单独的子文件夹中
  • 根据请求的域,以静默方式重定向到 适当的子文件夹

    例如

    • 如果我们需要 somedomain .com www.somedomain.com www.somedomain.com/anything / (或任何此类变体)从 / home / www / /home/www/somedomain.com /

      如何做到这一点?


      这是我尝试过的(但鉴于 .htaccess 绝对是...... 不是我的事情,它很可能接近非感性......):

        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条)

相关推荐 更多相似问题