【问题标题】:redirect and rewrite url重定向和重写 url
【发布时间】:2015-04-19 18:29:30
【问题描述】:

我的服务器上有一个客户的网站,客户有自己的域。

我想将源文件保留在我的服务器上,只是为了重定向客户域以显示来自我的服务器的网站内容。

  1. 客户域名:www.a.com
  2. 网站源文件:www.b.com/customer

我想在网络浏览器 www.a.com 中打开,显示来自 www.b.com/customer 的内容,但要将 www.a.com 保留在网络浏览器的地址栏中(包括来自 www.b.com 的子文件夹/客户)。

配置: 我正在使用托管服务器,无法编辑 apache 或 php 配置,源网站是用 CodeIgniter 编写的。在 CodeIgniter 中,我将 config.php 作为基本 URL:www.a.com。 www.a.com 在一台服务器上(我有 FTP 访问权限),根目录中有 .htaccess 文件:

RewriteEngine on
RewriteCond %{HTTP_HOST} ^a.com [NC,OR]
RewriteCond %{HTTP_HOST} ^www.a.com [NC]
RewriteRule ^(.*)$ http://b.com/customer/$1 [L,R=301,NC]

在我的服务器上是 www.b.com/customer,在 /customer 文件夹中还有一个 .htaccess 文件:

RewriteEngine On
RewriteBase /customer
RewriteCond $1 ^(application|system|private|logs)
RewriteRule ^(.*)$ index.php/access_denied/$1 [PT,L]
RewriteCond $1^(index\.php|robots\.txt|favicon\.ico|public|assets|css|js|images)
RewriteRule ^(.*)$ - [PT,L]
RewriteRule / index.php/$1 [PT,L]

在网络浏览器中隐藏“index.php”。 到目前为止一切正常,在调用 www.a.com 时,用户被重定向到 www.b.com/customer,页面正确显示。所有链接都显示为:“www.a.com/some_page.php”并且也可以正常工作。 唯一的问题是,在网络浏览器的地址栏中,用户看到的是“www.b.com/customer”。我想有'www.a.com/some_page.php' 这是详细的问题描述 - 请让我知道是否可以解决? 谢谢和最好的问候, 火石

【问题讨论】:

  • 您好,这个还是没有解决。有人可以帮帮我吗?

标签: .htaccess redirect mask


【解决方案1】:

我认为这也可以通过这个来解决 -> 在您的服务器上创建一个指向该目录 www.b.com/customer 的子域。比停放他的域,并将其作为您的子域的别名。

对于通过 .htaccess 的解决方案,我认为它类似于.htaccess rewrite to redirect root URL to subdirectory

【讨论】:

    【解决方案2】:

    (请参阅下面的编辑)
    您应该查看虚拟主机(或虚拟主机)。所有主要的 Web 服务器都支持 vhost。

    您应该将您的客户文件组织在您的网络根目录中,

    ---/var/www | --- customer_a/public_html | --- customer_b/public_html | …… | --- customer_z/public_html

    对于 Apache2,
    在站点可用目录中为每个客户创建配置文件,

    customer_a -> /etc/apache2/sites-available/a.com.conf
    customer_a -> /etc/apache2/sites-available/b.com.conf
    ...
    customer_z -> /etc/apache2/sites-available/z.com.conf

    customer_a的配置,(其他同理)

    <VirtualHost *:80>
        ServerAdmin webmaster@a.com
        DocumentRoot /var/www/customer_a/public_html
        ErrorLog ${APACHE_LOG_DIR}/customer_a/error.log
        CustomLog ${APACHE_LOG_DIR}/customer_a/access.log combined
    </VirtualHost>
    

    对于 lighttpd,

    $HTTP["host"] =~ "(^|\.)a\.com$" {
        server.document-root = "/var/www/customer_a/public_html"
        server.errorlog = "/var/log/lighttpd/customer_a/error.log"
        accesslog.filename = "/var/log/lighttpd/customer_a/access.log"
    }
    

    对于 nginx,
    在站点可用目录中为每个客户创建配置文件,

    customer_a -> /etc/nginx/sites-available/a.com
    customer_a -> /etc/nginx/sites-available/b.com
    ...
    customer_z -> /etc/nginx/sites-available/z.com

    customer_a的配置,(其他同理)

    server {
            listen   80; ## listen for ipv4; this line is default and implied
            #listen   [::]:80 default ipv6only=on; ## listen for ipv6
    
            root /var/www/customer_a/public_html;
            index index.html index.htm;
    
            # Make site accessible from http://localhost/
            server_name a.com;
    }
    

    编辑:

    因此,对于您的情况,(仅显示 Apache2 配置)
    /etc/nginx/sites-available/a.com 的内容应该是,

    <VirtualHost *:80>
        ServerAdmin webmaster@a.com
        DocumentRoot /var/www/customer_b/public_html
        ErrorLog ${APACHE_LOG_DIR}/customer_a/error.log
        CustomLog ${APACHE_LOG_DIR}/customer_a/access.log combined
    </VirtualHost>
    

    【讨论】:

      猜你喜欢
      • 2016-06-27
      • 2016-06-18
      • 1970-01-01
      • 2012-12-10
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多