[Webinar] Streamline your web hosting managementRegister Today

  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 289
  • Last Modified:

how to redirect browsers to the proper subfolder depending on what url was typed in

I have web hosting with 1and1 on a linux package. There are several domains in the package, and if I go to any of the domains I get the index.html that is in the root folder of my package. What I need to have happen is that someone browsing goes to the index.html that is in a subdirectory under the root directory. The different subdirectories pertain to the different domains. I've done this before on a Windows host with a default .asp file. I put a sample in the "code" section here. The sample will use domains  a.com, b.com, and c.com. I believe I will now how to do this with a perl script or a .htaccess file, or both, but I'm not sure
host = Request.ServerVariables("HTTP_HOST")
if host = "a.com" or host = "www.a.com" then
elseif host = "b.com" or host = "www.b.com" then
elseif host = "c.com" or host = "www.c.com" then
end if

Open in new window

1 Solution
Michel PlungjanIT ExpertCommented:
bwierzbickiAuthor Commented:
Ok, I tried the code below. I put .htaccess in the root folder, I have subfolders a, b, c and when I entered the website I got:
Internal Server Error
The server encountered an internal error or misconfiguration and was unable to complete your request.
Please contact the server administrator, webadmin@kundenserver.de and inform them of the time the error occurred, and anything you might have done that may have caused the error.
More information about this error may be available in the server error log.
Additionally, a 500 Internal Server Error error was encountered while trying to use an ErrorDocument to handle the request.

Options +ExecCGI
RewriteEngine On
RewriteBase /

# if the internal redirect in the 2nd rewriterule works this
# rule stops the rewriteengine from looping continually
RewriteCond %{ENV:REDIRECT_STATUS} ^200.*
RewriteRule ^ - [L]

# the http_host is http://www.example.com or example.com or
# example2.com etc. This grabs whatever is before the .com
# and after the www. so it will be example or example2 or example3
# and puts that in the variable %2. so this redirects internally requests
a.com-> from / -> /a/
b.com-> from / -> /b/
c.com-> from / -> /c/
# example4.com-> from / -> /example4/
# so a request for example3.com/test/index.html is served from
# /var/vhosts2/henrik/public_html/example3/test/index.html
RewriteCond %{HTTP_HOST} ^([a-z]+\.)?(.+)\.[a-z]+$ [NC]
RewriteRule ^(.*)$ %2/$1[L]

Featured Post

The 14th Annual Expert Award Winners

The results are in! Meet the top members of our 2017 Expert Awards. Congratulations to all who qualified!

Tackle projects and never again get stuck behind a technical roadblock.
Join Now