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?

5 Answers 5

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...

1
  • There's an error in example. Use window.location.assign("cars.mywebsite.com");
    – afilipko
    May 18, 2016 at 21:22
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

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?

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.

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.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.