![]() |
| Redirect Scripts |
|
tmetz
|
One issue that comes up fairly frequently is people wanting to point multiple domain names at a hosting space and have them redirected to subdirectories (our policy is that we will point additional domains at the root directory for you, but you've got to do the rest!). This requires a redirect script, and people often ask if we know of one. I thought I'd maybe start a thread with scripts in various languages.
To start us off, here is a link to one in ASP: http://www.planet-source-code.com/vb/scripts/ShowCode.asp?txtCodeId=6125&lngWId=4 And PHP: http://www.zend.com/tips/tips.php?id=67&single=1 Anyone else? |
||||||||||||
|
|
|||||||||||||
| Just what I have been looking for... |
|
Suzanne Kirkland
|
I have my websites here at host my site and I have been combing the internet for this very thing for the past 2 weeks. I was elated to find this thread right in my own backyard
<%@ Language=VBScript %> <% response.buffer = True %> <% 'Set up the redirect variables Dim strURL 'This is the URL the user typed into the browser Dim strSiteName 'This is the domain name Dim intEPos 'This is the position of the remaining dot strURL = Request.servervariables("HTTP_HOST") intURLLen = len(strURL) if inStr(1, UCase(strURL), "WWW") > 0 Then strURL = Right(strURL, (intURLLen - 4)) End if intEPos = inStr(1, strURL, ".") strSiteName = UCase(Mid(strURL, 1, (intEPos - 1))) Select Case strSiteName Case "obhenterprises.com" Response.redirect "http://www.obhenterprises.com/f1/index.htm" Case "Troop96.net" Response.redirect "http://www.troop96.net/f2/index.htm" Case Else Response.write "Site cannot be found" End Select %> |
||||||||||||
|
|
|||||||||||||
| Check your CASE case |
|
eflamm
|
Suzanne,
I think the problem is that you're upper-casing the strSiteName (UCase(strURL)), then testing it against mixed-case literals (Case "obhenterprises.com" ) - try making your text strings Upper Case as well ("OBHENTERPRISES.COM") and see if it works. Eric |
||||||||||||
|
|
|||||||||||||
|
Suzanne Kirkland
|
Thanks for responding. I am learning asp and VB script for the sole purpose of doing this redirect script so I am not too familiar with the languages as yet. For the benefit of other 'newbies' who are also trying to do this, I discovered that not only does the code change the string to upper case, but it also strips off the preceding "www." and trailing ".com". It is important to test only for the main portion of your domain name in the Select Case test string - e.g., Case "DOMAIN".
|
||||||||||||
|
|
|||||||||||||
|
mgibbons
|
Here is the asp code for redirecting to a folder. You can use it by itself on the index page with the else statement, or remove the else statement and incorporate it into an existing index page. Regardless, this code will obviously only work on a page with the .asp extension:
<% if (Request.ServerVariables("server_name") = "mike-gibbons.com") or (Request.ServerVariables("server_name") = "www.mike-gibbons.com") Then Response.Redirect ("/MikeGibbons/index.html") else ("/index.html") end if %> I use this on mgibbons.com, which is just a bogus site for showing customers stuff like this. |
||||||||||||
|
|
|||||||||||||
|
rora
|
Use server side settings.
|
||||||||||||
|
|
|||||||||||||
| Redirect script in PHP |
|
tofuninja
|
I just tested this one out, and it works nicely for me:
http://forum.joomla.org/index.php?topic=24206.msg142493 I don't know if copying/pasting from their site is allowed, but the post with the code in it was made by CubaLibre. |
||||||||||||
|
|
|||||||||||||
|
jamie
HostMySite Sales Rep
![]()
|
For the sake of completeness, here is a redirect script based in CF to address the use of subdomains on an account that only allows one domain name:
<CFIF FindNoCase("sub1.domain.com","#CGI.SERVER_NAME#") GT 0> <CFLOCATION URL="/sub1"> <CFELSEIF FindNoCase("sub2.domain.com","#CGI.SERVER_NAME#") GT 0> <CFLOCATION URL="/sub2"> <CFELSEIF FindNoCase("sub3.domain3.com","#CGI.SERVER_NAME#") GT 0> <CFLOCATION URL="/sub3"> <CFELSE> You came to unknown domain. </CFIF> |
||||||||||||
|
|
|||||||||||||
|
Josh
Forum Regular
|
HMS won't do that. |
||||||||||||||
|
|
|||||||||||||||
| Redirect Scripts |
|
||
|



