Question

How to mod rewrite a secondary domain pointed to 1 IP to a specific file with query string?

I have 2 domains:

  1. example-1.com points to 12.34.56
  2. example-2.com also points 12.34.56

Both domains have the same DocumentRoot setup in VirtualHost:

First looks like:

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

Second looks like:

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

However, I want the second domain to redirect to a specific file with a special query to display different content. On my local host I have been able to get this setup to work, but I have been unsuccessful at mimicking this on my remote DO Ubuntu server.

I’m currently rewriting using mod rewrite conditioning. This is my local setup:

<IfModule mod_rewrite.c>
  RewriteEngine On
  RewriteCond %{HTTP_HOST} ^example-2.com
  RewriteRule ^$ page.php?foo=bar[QSA]
</IfModule>

The first domain, example-1.com by default will showcase page.php content without any mod rewrite rules or query needed as I have designed it to do so. The second domain, example-2.com on the other hand will need to show specific content different from what example-1.com shows. Again, this all works locally for me, but when I imitate this all on the remote server I get no dice. Any help would be greatly appreciated, thanks!

Subscribe
Share

Submit an answer
You can type!ref in this text area to quickly search our full set of tutorials, documentation & marketplace offerings and insert the link!

These answers are provided by our Community. If you find them useful, show some love by clicking the heart. If you run into issues leave a comment, or add your own answer to help others.

Accepted Answer

Disregard, I came up with an alternative solution which I think is a better one. I’m controlling each requested domain/host from within the scheme of the program, and serving up the content accordingly. :)