Mask subdomain.mydomain1.com to subdomain.mydomain2.com

ぃ、小莉子 提交于 2019-12-11 17:08:59

问题


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]

回答1:


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.




回答2:


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?



来源:https://stackoverflow.com/questions/46469497/mask-subdomain-mydomain1-com-to-subdomain-mydomain2-com

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!