Consider abc.com is my main website using nameservers ns1.testnameserver.com & ns2.testnameserver.com.
I would like to redirect multiple domains as below:
def.com to abc.com/products/def ghi.com to abc.com/products/ghi jkl.com to abc.com/products/jkl mno.com to abc.com/products/mno I tried the below:
i set the same testnameserver for def.com,ghi.com,jkl.com,mno.com.
tried some combination in RewriteCond and .htaccess but i couldn't solve it.
Anyone guide me to move further.
Thanks all.
Note:
I can't use domain forwarding / host all the domains because it's should be dynamic (like 3500+ domains to 3500+ products)
3 Answers
Answers 1
You can achieve this using below steps -
You need to setup the zone file for each domain having an A record entry pointing to IP address of abc.com.
On abc.com web server, you can write an script in any language of your choice which will read the host and appropriately does a redirect to wherever you need.
Alternatively you could do this from .htacess too, but since you have a large amount of domains, so I would suggest to go with a script in any language (php, python etc.)
Answers 2
You can do exactly what you are looking for with a RewriteMap directive.
First place your mappings in a file, e.g. /var/lib/domains.txt containing
def.com http://example.net/products/def ghi.com http://example.net/products/ghi jkl.com http://example.net/products/jkl mno.com http://example.net/products/mno Then you set up the following rules in a server or virtual host .conf -file (you cannot do this in a .htaccess file):
RewriteEngine On RewriteMap lowercase int:tolower RewriteMap custdomains txt:/var/lib/domains.txt # rewrite matching domain to desired URL RewriteCond ${lowercase:%{HTTP_HOST}} ^(?:www\.)?(.+) RewriteCond ${custdomains:%1} ^(.+)$ RewriteRule ^/(.*)$ %1 [R=301,L,NE] # unmatched domains are passed unchanged RewriteRule . - [R,NE,L] The RewriteCond -rules will capture the HTTP_HOST header containing the hostname of the target domain the user is browsing to. If that hostname matches a mapping defined in your textfile, the browser will be redirected to the matching URL.
With this setup you can point all your thousands of domains to the same server, which then performs suitable redirects based on the mappings in an external file (which you can update without having to restart apache). For better performance, you should really use an external DBM Hash File instead (see the documentation for RewriteMap for details).
Answers 3
I'm not sure I understand your problem, but you can redirect domains with:
RewriteEngine on # not for exemple.com RewriteCond %{HTTP_HOST} !example\.com$ [NC] RewriteCond %{HTTP_HOST} (?:^|\.)([^.]+)\.(?:[^.]+)$ RewriteRule ^ http://example.com/products/%1%{REQUEST_URI} [NE,L] Point all your DNS on the main website, and just change the name of the main domain (example.com) in this .htaccess
0 comments:
Post a Comment