locked
Simple URL Rewrite RRS feed

  • Question

  • User-2108369543 posted

    hi,
    My current application is with mvc3 in visual studio 2010.i deployed in IIS 7.5 server in local host.My url is
    http://localhost:80/nVisionOfficeMVC.I want the urls like http://localhost:80/uncd.nVisionOfficeMVC or
    http://localhost:80/fsc.nVisionOfficeMVC,http://localhost:80/gbc.nVisionOfficeMVC etc to redirect to
    http://localhost:80/nVisionOfficeMVC.

    after reading and searching i try to create rule by URL rewrite in IIS.test the rule in URL Rewrite window.it succeeded,
    but from browser i get

    HTTP Error 404.0 - Not Found
    The resource you are looking for has been removed, had its name changed, or is temporarily unavailable.

    can anyone please write the full process and what is the reqular expression/wildcard for the above scenerio

    sabbir

    Wednesday, March 19, 2014 8:40 AM

Answers

  • User1508394307 posted

    <rule name="rule1" stopProcessing="true">
    <match url="^\w+\.nVisionOfficeMVC$" />
    <action type="Redirect" url="/nVisionOfficeMVC" />
    </rule>

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Thursday, March 20, 2014 3:05 AM

All replies

  • User1508394307 posted

    <rule name="rule1" stopProcessing="true">
    <match url="^\w+\.nVisionOfficeMVC$" />
    <action type="Redirect" url="/nVisionOfficeMVC" />
    </rule>

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Thursday, March 20, 2014 3:05 AM
  • User-2108369543 posted

    Dear smirnov,Thanks for ur reply.It does not work.can u give some url sample for which the above redirect will work..

    Thursday, March 20, 2014 3:42 AM
  • User1508394307 posted

    "It does not work" does not tell me that much. What url you tested and what was the result? If you mean you got 404 then what is the url you were redirected (you can see it in the address bar of the browser)?

    Thursday, March 20, 2014 4:02 AM
  • User-2108369543 posted

    I have no www. it is deployed in the localhost. so i removed ^\w+.I also removed $.I have allatched two screenshot.My site is deployed under DefaultWebSite .I am adding rules to mysite,not to DefaultWebSite.it it the problem?.

    Please see the screenshots

    http://postimg.org/image/h3oianyjn

    http://postimg.org/image/w70yavfox/

    Thursday, March 20, 2014 4:29 AM
  • User-2108369543 posted

    Problem solved.I just add the modified setting to DefaultWebSite under which mysite reside and it works.thanks :)

    Thursday, March 20, 2014 4:41 AM
  • User1508394307 posted

    Glad it works now for you.

    Small correction:

    \w stays for alphanumeric characters and equal to [a-zA-Z0-9] 
    + stays for one or more (character)
    ^ means the match is in the beginning of string

    In other words, it has no connection to "www." and it has no connection to a domain name. I added that part (^\w+) to match strings like 

    /uncd.nVisionOfficeMVC

    if you only use "\.nVisionOfficeMVC$" as a rule then it would also match 

    /.nVisionOfficeMVC

    If this is not a problem for you then it is fine.

    Thursday, March 20, 2014 4:51 AM
  • User-2108369543 posted

    Hi smirnov ,thanks again for your last post.I want to share two things to take your suggestion.

    Firstly,It is a single page application(spa).MY url is http://localhost/nVisionOfficeMVC/Home/Index.Default route's controller & action is user & login respectively.So when ihit http://localhost/nVisionOfficeMVC/Home/Index it goes to http://localhost/nVisionOfficeMVC for authuntication.In this authentication page if i modify url to http://localhost/uncd.nVisionOfficeMVC, it is ridirecting to http://localhost/nVisionOfficeMVC which is correct and it proves url redirect is working correctly.But after login the url is http://localhost/nVisionOfficeMVC/Home/Index,and then if i modifiy the url to http://localhost/uncd.nVisionOfficeMVC/Home/Index ,it is rediecting to http://localhost/nVisionOfficeMVC(login view).What can i do to keep it in http://localhost/nVisionOfficeMVC/Home/Index instead of login View.Is Rewrite more applicable instead of Redirect?

    Secondly,My application is on mvc3,vs 2010.In my loging view, i have a field name Account with login and Password.Different Company's user put their company name(uncd,fsc,gbc etc) in Account field.The new requirement is account field will be taken from url (http://localhost/uncd.nVisionOfficeMVC/Home/Index,have to take uncd,http://localhost/fsc.nVisionOfficeMVC/Home/Index,have to take fsc etc) and hosting will be in one domain in one virtual path(/nVisionOfficeMVC).The url must be in http://localhost/uncd.nVisionOfficeMVC/Home/Index format,not like http://localhost/nVisionOfficeMVC/Uncd/Home/Index or anything else.

    Please write your suggestion.thanks :)

    Thursday, March 20, 2014 11:25 PM
  • User1508394307 posted

    What is the reason of having different urls for the same content? It sounds unusual and incorrect.

    Friday, March 21, 2014 4:54 AM
  • User-2108369543 posted

    It's the requirment of the owner of the software :).any other suggestion?

    Friday, March 21, 2014 8:56 AM
  • User1508394307 posted

    it is rediecting to http://localhost/nVisionOfficeMVC(login view).What can i do to keep it in http://localhost/nVisionOfficeMVC/Home/Index instead of login View.Is Rewrite more applicable instead of Redirect?

    You need to check how the redirect is performed. 

    If this is because of your rule 

    <action type="Redirect" url="/nVisionOfficeMVC" />

    then change it as

    <action type="Redirect" url="/nVisionOfficeMVC/Home/Index" />

    if this is because of using Contoller.Redirect - then try to use RedirectToAction()

    Friday, March 21, 2014 9:37 AM