zoukankan      html  css  js  c++  java
  • [Ubuntu] apache .htaccess根据访问的域名指向不同的目录

    情景如下:

    http://sh.test.local 指向 test_sh 目录

    http://gz.test.local 指向 test_gz 目录

    使用域名 http://img.test.local专门用来放图片,以便浏览器加载的,

    但事实上是, http://img.test.local 是要根据不同主访问来指定不同的图片目录的,比如说,

    通过 http://sh.test.local 的时候,访问的是 test_sh/upload/images 里面的文件

    通过 http://gz.test.local 的时候,访问的是 test_gz/upload/images 里面的文件

    这时候,就要通过迂回的方法来做了。

    创建目录 test_img,apache创建virtualhost,指到 test_img,如

    <VirtualHost *:80>
        <Directory "/path/to/webroot/test_img">
        </Directory>

        DocumentRoot "/path/to/webroot/test_img"
        ServerName img.test.local
        ServerAlias img.test.local
    </VirtualHost> 

    在 test_img 下面建立文件 .htaccess,内容如下:

    RewriteEngine on
    RewriteCond %{HTTP_REFERER} ^http://gz.test.local/.*$ [NC]
    RewriteRule ^(.*)$ http://gz.test.local/$1 [R=301,L]
    RewriteCond %{HTTP_REFERER} ^http://sh.test.local/.*$ [NC]
    RewriteRule ^(.*)$ http://sh.test.local/$1 [R=301,L]

    记得确保你的 apache 支持 rewrite,同时还要确定在 apache的配置文件里面是: 

    AllowOverride all 

    重启 apache

    sudo /etc/init.d/apache2 restart

    搞掂! 

  • 相关阅读:
    深度学习中的范数
    UML描述的模型中常见关系及表示方法
    tensorflow入门:CNN for MNIST
    tensorflow 梯度下降方法小结
    tensorflow dropout实现
    tensorflow xaiver初始化
    tensorflow入门:Neural Network for mnist
    tensorflow入门:Softmax Classication
    tensorflow入门:Logistic Regression
    Monitor关键字
  • 原文地址:https://www.cnblogs.com/davidhhuan/p/2800091.html
Copyright © 2011-2022 走看看