Hello web developers, I have a small problem and I am not sure if it's doable using just htaccess or should I use php file_get_contents();

I have 2 sites ...

example-1.com and example-2.com

I want the content of example-1.com, whole site, to show on example-2.com.
And if someone visits example-2.com/about-us I want to show content for example-1.com/about-us

How can I do this?

Dani AI

Generated

Short answer: do not proxy each page with PHP. Mirror the site by serving both hostnames from the same document root on the server so example-2.com shows example-1.com content without visible redirects. was right that using file_get_contents() adds unnecessary HTTP overhead; was directionally correct about parked/alias domains but beware: registrar "park" often issues visible redirects, while a server-side alias keeps the URL intact.

Practical steps:

  1. Point example-2.com A/AAAA to the same server IP as example-1.com.

  2. Configure the webserver to accept both hostnames. For Apache, add the secondary name to the vhost (ServerAlias). Example:

    <VirtualHost *:80>
    ServerName example-1.com
    ServerAlias example-2.com www.example-2.com
    DocumentRoot /var/www/example1
    </VirtualHost>

    For nginx use multiple names in server_name. In cPanel use the Aliases (Parked Domains) or set the addon domain document root to the same folder. See the Apache VirtualHost docs and .

Important gotchas: if the app uses absolute URLs or forces a canonical domain (WordPress siteurl, CMS base_url), links will still point to example-1.com — change the app to honor the Host header or use relative URLs, or implement domain-aware config (WordPress often needs multisite/domain-mapping or a dynamic siteurl). Also provision SSL certs for example-2.com (LetsEncrypt works fine) and pick a canonical strategy (rel=canonical or 301 redirects) to avoid duplicate-content issues in search engines.

Recommended Answers

All 6 Replies

Why not point both domain names to the same code so the site works with both? Would require a config change to your httpd.conf file and pointing both domain names to the same place.

Hi Dani, is it possible to do it with htaccess? I found some solutions online but it did not work for me. I am new to htaccess.

Also, no, this is not the appropriate use case for file_get_contents(). You would have incredibly poor performance doing it that way.

Hi Farrish, as Dani mentioned in a previous comment, the best solution is to create example-2.com as a parked domain of example-1.com and point to the same files.

A parked domain (also known as domain alias) shows the same content as the primary domain. The parked domain must be already registered and pointed to your nameservers.

I hope this helps.

Best regards.

This wouldn’t be a parked domain. A parked domain is the cheap method where you can pay your domain registrar a few bucks to do a 301 redirect from every URL of one domain to the other.

If you want to mirror the content, and not do visible redirects from one domain to the other with each page, you just want to point both domains to the same server IP address, and edit your Apache’s config file to listen for both domain names.

Can I do this with parked domain? If so, how?

I own both domain names. And yes, I want to mirror the first domain to the second one.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.