I have a domain name (example2.com) that is going to serve to direct a user to a specific page of another website on the same server (example.com/page2). I am following the instructions in this article for creating a redirect without changing the URL, see example 2, but must be doing something wrong because the affect I am getting is either an error message or it is loading the dummy content on the index.html. When I delete the index.html, I get:
Not Found The requested URL / was not found on this server" as one would expect with no index.html.
I have set up a new vhost in apache by creating an example2.com.conf
in sites-available and created a symlink in sites-enabled. I created a dummy index.html and defined the docroot in the example2.com.conf
file. All good so far, the dummy content loads.
The entire contents of my .htaccess
file in the docroot of example2.com are as follows:
RewriteEngine on
RewriteCond %{HTTP_HOST} ^example2.com
RewriteRule ^(.*) http://www.example.com/page2 [P]
Any links on the page that I want the domain to load are either external, or are allowed to go to example.com as normal. It's an unbranded partner project page, built using Drupal. The domain name (example2.com) needs to load (example.com/page2) but show example2.com in the address bar. This is the only content for the domain name so I only created a docroot for it for the sake of testing dummy content and creating the .htaccess.
Apache and Debian 9.
I've also tried some suggestions from this post, many of which say you can't do it using a .htaccess file. I've also tried the suggestions in the answers below.
Note: this question has had a major rewrite as I've gotten closer at at explaining what I'm trying to do.
mod_rewrite
.