0

Looking for the most transparent way (for the visitor) to be redirected to a subdomain from a page on the www site. IIS is the server. Example:

www.mywebsite.com/cars ---> cars.mywebsite.com

Any suggestions?

Kurt Emch
  • 529
  • 4
  • 17

5 Answers5

2

Well, if you want the solution in javascript, then its pretty easy. Just find out the first JS file thats loaded and add this on the TOP

if(document.url == "www.mywebsite.com/cars")
window.location("cars.mywebsite.com");

Just mentioned since you've mentioned javascript and html in the tags...

Riju Mahna
  • 6,718
  • 12
  • 52
  • 91
1

Javascript might be a bit of a clunky solution.

I'd recommend you go with something on the server side that will be easier to maintain.

  • Create the 'cars' directory
  • Create an empty web.config in the 'cars' directory

Put the following contents into the web.config file

<?xml version="1.0"?>
<configuration>
<system.webServer>
  <httpRedirect enabled="true" destination="http://cars.mywebsite.com" httpResponseStatus="Permanent" />
</system.webServer>
</configuration>

This probably won't work within visual studio's web server, but should be fine in IIS

thejayjay
  • 68
  • 1
  • 5
0

In case you are looking for the redirect in IIS server, the answer may lie in this post:

How to redirect a URL path in IIS?

Community
  • 1
  • 1
Riju Mahna
  • 6,718
  • 12
  • 52
  • 91
0

imho htaccess would re-direct the user before any data is sent to the client.

Example: in teh root dir you want the user directed -from- place a file called .htaccess with the contents of:

#Redirect old file path to new file path
Redirect /olddirectory/oldfile.html http://cars.example.com/newdirectory/newfile.html

Source: http://kb.mediatemple.net/questions/242/How+do+I+redirect+my+site+using+a+.htaccess+file%3F

Hope that helps Kurt.

David J Eddy
  • 1,999
  • 1
  • 19
  • 37
0

If you're looking for single solution - then @Riju's answer is a good one.

But for a more general solution, URL Rewriter for IIS is pretty powerful and will allow you to create rules things like this, and many more situations.

freefaller
  • 19,368
  • 7
  • 57
  • 87