Forum Moderators: phranque
I signed up for webspace on Powweb and registered two domain names. I was told I could use both domains but that I would have to buy a tool that would manage the .htaccess file. I thought I could maybe save the 30 bucks and figure it out myself, but I'm struggling. Here's what I've got in the .htaccess file now:
RewriteEngine on
RewriteCond %{HTTP_HOST} ^www.domain1.org$
RewriteRule ^(.*)$ [domain1.org...] [R=301,L]
RewriteCond %{HTTP_HOST} ^www.domain2.com$
RewriteRule ^(.*)$ [domain2.com...] [R=301,L]
And when I type in the address (for either one), I get:
"Redirection limit for this URL exceeded. Unable to load the requested page. This may be caused by cookies that are blocked."
?
You'll need to explicitly exclude previously-redirected requests. I'd also suggest that you don't use a redirect at all, because this will 'expose' your folder structure to visitors, and make your URLs 'look funny.' Instead, simply rewrite the requests to the appropriate subfolder:
RewriteCond $1 !^folder1/
RewriteCond %{HTTP_HOST} ^www\.domain1\.org
RewriteRule (.*) /folder1/$1 [L]
#
RewriteCond $1 !^folder2/
RewriteCond %{HTTP_HOST} ^www\.domain2\.com
RewriteRule (.*)/folder2/$1 [L]
# prevent rewrite loop
RewriteCond $1 !ds_
# check for main domain (to be excluded from rewrites)
# RewriteCond %{HTTP_HOST} !^(www\.)?maindomain\.com
# extract domain name
RewriteCond %{HTTP_HOST} ^(www\.)?([^.]+)\.([^.:]+)
# check that domain-subfolder exists
RewriteCond %{DOCUMENT_ROOT}ds_%1%2/ -d
# rewrite to domain subfolder
RewriteRule (.*) /ds_%1%2/$1 [L]
Another point is that you may indeed wish to move your main domain into a subfolder as well, to ease site maintenance. To do that, all you have to do is omit the second RewriteCond and move the physical files into an appropriately-named subfolder.
This code is untested, and may be missing a slash here or there. But it should serve as a good starting point.
Jim