2 domains 1 host -> domain url rewrite

2019-08-13 03:24发布

问题:

i have a (php) wordpress site on let's say domain1.com and i bought another domain and pointed it to the same host as domain1.com...

So now, i have that one hosting account which serves the wordpress site and when i put domain1.com in the address bar, i get that page. When i put domain2.com, I also get that same page (becouse I redirected domain2.com to point to my hosting account), and that's fine. But how can I have 2 domains point to the same host, and keep the domain prefix user inputed.. so that when user inputs domain1.com/index.php or domain2.com/index.php, he would be served the same page from the server, but the user would have a different address in his address bar?

I hope my question is clear.

Thank you for your time...

回答1:

That is not possible: you can of course to point 2 domains to the same web, but WordPress save internally his full location, so if you install WP on domain1 and then you access it from domain2, when you do clic over a link, the next page will be of domain1.

I suggest you to use only one domain and redirect the second to the first one (with rewrite rules for example).



回答2:

You have to setup some kind of virtual hosting with your server.

Create an additional file on you conf.d directory.

Something like this should work:

<VirtualHost *:80>
        ServerName domain1.com
        DocumentRoot /var/www/domain1
        <Directory /var/www/domain1>
                Options Indexes FollowSymLinks
                AllowOverride All
                order allow,deny
                allow from all
        </Directory>
</VirtualHost>
<VirtualHost *:80>
        ServerName domain2.com
        DocumentRoot /var/www/domain2
        <Directory /var/www/domain2>
                Options Indexes FollowSymLinks
                AllowOverride All
                order allow,deny
                allow from all
        </Directory>
</VirtualHost>


回答3:

so what I finally did was ->

change the dns on the new domain to point to my hosting account and through cpanel add that new domain as "parked domain"..

maybe this could help someone..