I've two domain names for the similar website.

I've got a single page on my small site I wish to seem to range from second domain (within this example it's example2.com/pagex). With exception to root and pagex, other demands to example2.com ought to be rerouted to example1.com.

All pages on my small site appear as sites but they are really just index.php?page=pagename because of mod_rewrite rules proven below.

Here's my .htaccess file:

RewriteEngine on

RewriteCond %{HTTP_HOST} ^(www\.)?example2\.com [NC]
RewriteCond %{REQUEST_URI} !^/$ #Do not redirect root
RewriteCond %{REQUEST_URI} !^/pagex/ #Do not redirect pagex
RewriteRule ^(.*)$ http://www.example1.com/$1 [R=301]

# If the file or folder does not exist, send to index.php as variable
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^([^/\.]+)/?$ /index.php?page=$1 [L]

Running the above mentioned code by visiting example2.com/pagex/ I recieve rerouted to world wide web.example1.com/index.php?page=pagex. The 2nd condition must have unsuccessful, stopping the redirect. What's even stranger may be the virtual directory continues to be changed using the actual path.

You are able to write your rules such as this:

RewriteEngine on
Options +FollowSymlinks -MultiViews

RewriteCond %{HTTP_HOST} ^(www\.)?example2\.com [NC]
RewriteCond %{THE_REQUEST} !/pagex/? [NC]
RewriteRule ^(.+)$ http://www.example1.com/$1 [R=301,L]

# If the file or folder does not exist, send to index.php as variable
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^([^/\.]+)/?$ /index.php?page=$1 [L]

With above code http://example2.com/pagex/ will get properly rerouted to http://example2.com/index.php?page=pagex