Solved

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

Posted on 2009-05-03
2
274 Views
Last Modified: 2012-05-06
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
<%EnableSessionState=False
 
host = Request.ServerVariables("HTTP_HOST")
 
if host = "a.com" or host = "www.a.com" then
response.redirect("http://a.com/a/index.htm")
 
elseif host = "b.com" or host = "www.b.com" then
response.redirect("http://b.com/b/index.html")
 
elseif host = "c.com" or host = "www.c.com" then
response.redirect("http://c.com/c/index.htm")
 
else
response.redirect("http://a/a/index.htm")
 
end if
%>

Open in new window

0
Comment
Question by:bwierzbicki
2 Comments
 
LVL 75

Accepted Solution

by:
Michel Plungjan earned 500 total points
ID: 24293609
0
 

Author Comment

by:bwierzbicki
ID: 24294968
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]
0

Featured Post

Master Your Team's Linux and Cloud Stack!

The average business loses $13.5M per year to ineffective training (per 1,000 employees). Keep ahead of the competition and combine in-person quality with online cost and flexibility by training with Linux Academy.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

The following is a collection of cases for strange behaviour when using advanced techniques in DOS batch files. You should have some basic experience in batch "programming", as I'm assuming some knowledge and not further explain the basics. For some…
Active Directory replication delay is the cause to many problems.  Here is a super easy script to force Active Directory replication to all sites with by using an elevated PowerShell command prompt, and a tool to verify your changes.
Learn the basics of while and for loops in Python.  while loops are used for testing while, or until, a condition is met: The structure of a while loop is as follows:     while <condition>:         do something         repeate: The break statement m…
The viewer will learn how to count occurrences of each item in an array.

770 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question