Creating domain aliases mapping to wildcard domains

  Kiến thức lập trình

I want to do something like wix.com and accept all external domains requests, i.e. my server accepts requests to all domains which point to our server ip.

I have an existing wildcard domain setup:

  • *.site1.com points to sites root folder
  • *.site2.com points to stores root folder

The contents are mapped using rules like:

RewriteCond %{HTTP_HOST} !site1.com$ [NC]       
RewriteCond %{HTTP_HOST} ^(?:www.)?(.+?)$          
RewriteCond %{REQUEST_FILENAME} !-f             
RewriteCond %{REQUEST_FILENAME} !-d         
RewriteRule (.*) /%1/$1 [L] 

Now I want to create aliases for these domains, e.g.:

example.com    =>  mm.site1.com
test.net       =>  dd.site1.com

domain.com     =>  tt.site2.com
test2.com      =>  ss.site2.com

I’ve tried using RewriteMap:

RewriteMap domainMap txt://path/to/map.txt

map.txt contents :

example.com    =>  mm.site1.com
test.net       =>  dd.site1.com

domain.com     =>  tt.site2.com
test2.com      =>  ss.site2.com

I know following htaccess not correct but it’s near to what I want:

Options +FollowSymLinks -MultiViews
RewriteEngine on
RewriteCond %{HTTP_HOST} ^(.*).site1.com$ [NC]
RewriteRule ^$ ${domainMap:%1} [L,R]
RewriteCond %{HTTP_HOST} !site1.com$ [NC]       
RewriteCond %{HTTP_HOST} ^(?:www.)?(.+?)$          
RewriteCond %{REQUEST_FILENAME} !-f             
RewriteCond %{REQUEST_FILENAME} !-d         
RewriteRule (.*) /%1/$1 [L] 

What is the best way to do that ?

Theme wordpress giá rẻ Theme wordpress giá rẻ Thiết kế website

LEAVE A COMMENT