Forum Moderators: phranque

Message Too Old, No Replies

How to redirect more domains in one folder via .htaccess

domain redirect httacces one directory

         

zbv2net

10:31 am on Aug 17, 2007 (gmt 0)

10+ Year Member



hi i have a web hosting from powweb and i can add multiple domains but they all are to one directory / home

how can i make a .htaccess redirect so when i add one domain to redirect to that domain but other folder

like 1domain.com to redirect to 1domain.com/domain1/

2domain.com to redirect to 2domain.com/domain2/

i whant if possible for both www and with no www oth to redirect

thank you

jdMorgan

2:41 pm on Aug 17, 2007 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



The answeer is very similar to this thread [webmasterworld.com], which discusses mapping subdomains to subdirectories.

Note that you do not use an external redirect, you use an internal rewrite. In this way, the subdirectories are never exposed to the client, and each appears to be a stand-alone domain.

Jim

zbv2net

4:01 pm on Aug 17, 2007 (gmt 0)

10+ Year Member



i found the answer and thats not the answer here is it

because the company is asking 7$ for a domain redirect like that

i wanted to redirect because all domains point to one directory and now every domain pints to its directory

where the main domain is other

and here it is

RewriteEngine On

RewriteCond %{HTTP_HOST} ^domain2.com$ [OR]
RewriteCond %{HTTP_HOST} ^www.domain2.com$
RewriteRule ^/?$ [domain2...] [R=301,L]

g1smd

6:07 pm on Aug 17, 2007 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



That code means the URL is indexed as a folder. You used a redirect.

If you want it indexed as a domain, then you need a rewrite. It is almost the same code, but without the [R=301] part included.

You'll also need to pick up the URL path in a (.*) and then use it in the rewrite using the $1 syntax.

The target URL of the rewrite should not include the "http://domain.com" part. It should only include the file path on the server.

jdMorgan

6:49 pm on Aug 17, 2007 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Well, it was the answer, but you didn't recognize it. You have several errors, omissions, and inefficiencies in your code, and you've created a potential infinite rewrite loop, along with missing the point that I made about external redirects versus internal rewrites that g1smd has now told you again.

RewriteCond $1 !^aod_
RewriteCond %{HTTP_HOST} ^(www\.)?(domain2\.com) [OR]
RewriteCond %{HTTP_HOST} ^(www\.)?(domain3\.com) [OR]
RewriteCond %{HTTP_HOST} ^(www\.)?(domain4\.com)
RewriteRule (.*) /aod_%2/$1 [L]

Store the domain2.com addon domain's files in a folder at /aod_domain2.com/, files for the domain3.com addon domain at /aod_domain3.com/, etc.

And just for good measure, add


RewriteCond %{THE_REQUEST} ^[A-Z]{3,9}\ /aod_
RewriteRule ^aod_ - [F]

to prevent people from "fishing around" in the aod_ addon subdirectories looking for files that belong to your addon domains, while not interfering with the rewrite.

Jim