Solved

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

Posted on 2009-05-03
2
272 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

Threat Intelligence Starter Resources

Integrating threat intelligence can be challenging, and not all companies are ready. These resources can help you build awareness and prepare for defense.

Join & Write a Comment

In this tutorial I will focus on how to use WhizBase as a tool for sending ICQ messages to ICQ. Here I will use a new technology in WhizBase, published in WhizBase 5.1 version. In this tutorial I will use 3 files, pager.wbsp for the processing, e…
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 lists in Python. Lists, as their name suggests, are a means for ordering and storing values. : Lists are declared using brackets; for example: t = [1, 2, 3]: Lists may contain a mix of data types; for example: t = ['string', 1, T…
Learn how to match and substitute tagged data using PHP regular expressions. Demonstrated on Windows 7, but also applies to other operating systems. Demonstrated technique applies to PHP (all versions) and Firefox, but very similar techniques will w…

760 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

Need Help in Real-Time?

Connect with top rated Experts

22 Experts available now in Live!

Get 1:1 Help Now