Mask subdomain.mydomain1.com to subdomain.mydomain

2019-09-17 16:56发布

I have got customer.mydomain1.com and want to mask it to customer.mydomain2.com

so that customer.mydomain1.com shows content of customer.mydomain2.com and url stays the same as of customer.mydomain1.com

I am using the code below used in my .htaccess, which gives me ERROR 400

RewriteEngine On
RewriteCond %{HTTP_HOST} ^customer.mydomain1.com
RewriteRule ^(.*) http://customer.mydomain2.com/$1 [P]

2条回答
Lonely孤独者°
2楼-- · 2019-09-17 17:07

I would just use a ServerAlias this works for any domain that have an A-Record or a CNAME pointing to your server:

<VirtualHost *:80>
    ServerName customer.mydomain2.com
    ServerAlias www.customer.mydomain2.com customer.mydomain1.com example.com

    DocumentRoot /var/www/path/to/public_html

    ErrorLog ${APACHE_LOG_DIR}/error.log
    CustomLog ${APACHE_LOG_DIR}/access.log common
</VirtualHost>

No need to use mod_rewite with mod_proxy (required for the the [P] Flag) All listed domains (you can add as many you like)

  • customer.mydomain2.com
  • www.customer.mydomain2.com
  • customer.mydomain1.com
  • example.com

will respond with the content of /var/www/path/to/public_html so just replace it with the public directory of your customer.mydomain2.com server.

查看更多
劳资没心,怎么记你
3楼-- · 2019-09-17 17:26

I can't see anything wrong in your config. I used this configuration on my local apache, so both domains are on the same HTTPD:

<VirtualHost *:80>
    ServerName customer.mydomain1.com
    ErrorLog "logs/error_mydomain1_log"
    CustomLog "logs/access_mydomain1_log" common

    RewriteEngine On
    RewriteCond %{HTTP_HOST} ^customer.mydomain1.com
    RewriteRule ^(.*) http://customer.mydomain2.com/$1 [P]

</VirtualHost>

<VirtualHost *:80>
    ServerName customer.mydomain2.com
    ErrorLog "logs/error_mydomain2_log"
    CustomLog "logs/access_mydomain2_log" common

    DocumentRoot "/home/tools/apache/htdocs/mydomain2"
    DirectoryIndex index.html
</VirtualHost>

Then changed my local hosts file to define both domains, and it works. I get the content of index.html if I access http://customer.mydomain1.com. I also created other files, in sub-directories on customer.mydomain2.com and when I access them, customer.mydomain1.com stays in the address bar.

So either there is something in your configuration, or some module is missing. Does $(apachectl -t) return "Syntax OK"? Did you restart your apache?

查看更多
登录 后发表回答