Remove folder in URL

Discussion in 'DNS/Domain names' started by tremors, Jan 6, 2011.

  1. I have 2 domain names: domain1.com and domain2.com.

    I am using the redirect script in the root to redirect each domain to it's own folder. This is working correctly. The problem I am having is that when it redirects to a folder it shows the folder name in the url after the domain name: (domain1.com/domain1).

    My question is can you mask it so show domain1.com instead of showing up as domain1.com/domain1 in the URL? Can you rewrite the URL?


    Thanks so much in advance!

    Anthony
     
  2. Ray

    Ray

    Last edited by a moderator: Oct 14, 2015
  3. I have tried to follow the instructions but no luck. I've downloaded IIS Manager and have tried creating the rules, Rewrite Maps, etc. I've read numerous blogs and forums.

    The bottom line is that I have 2 domains and use a redirect script in the root directory to redirect each domain to it's own folder since you can't add another domain to point to another folder.

    I still am unable to figure out how to mask my 2 domains (domain1.com and domain2.com) to show up as domain1.com and domain2.com and not domain1.com\folderthatcontiainsfiles1 and domain2.com\folderthatcontiainsfiles2.

    Any guidance or help would be greatly appreciated.

    Thanks!

    Anthony
     
  4. Ray

    Ray

    Copy and paste the redirect/rewrite rule on this thread so we can review the rule you created.
     
  5. I've tried a few of them but here is the latest one. Basically I want anything that has the /zh/ folder to be rewritten without that in the url...so for example domain1.com/zh/index.asp to be changed to domain1.com/index.asp. Not sure how to carry over the page that it's on and remove the folder from the URL

    Thank you so much for your help in advance!.

    Anthony



    <?xml version="1.0" encoding="UTF-8"?>
    <configuration>
    <system.webServer>
    <rewrite>
    <rules>
    <rule name="Rewrite rule1">
    <match url="/zh/" />
    <conditions>
    </conditions>
    <action type="Rewrite" url="/" appendQueryString="false" />
    </rule>
    </rules>
    </rewrite>
    </system.webServer>
    </configuration>
     
  6. Ray

    Ray

    Try this.

    Delete the old rule and recreate it following these steps.

    1. Log into IIS 7 Manager and go to the URL Rewrite module.
    2. Choose "Add Rule".
    3. Name your rule (i.e. rule1).
    4. For "Requested URL:" choose "Matches the Patter" and for the "Using" field choose "Regular Expressions".
    5. For the Pattern text box type (.*) make sure you add the parenthesis and check the check box "Ignore case".
    6. Add the conditions.
    Condition Input: {HTTP_HOST}
    Check if input String: Matches the Pattern
    Pattern: ^domain1\.com$

    Note: If you are going to also use www.domain1.com you will need to add another condition that will have the pattern reading ^www.domain1\.com$

    7. Leave the rest to its default state and go to the field that reads "Action Type". It should have a drop down list.
    8. On Action Type: choose Rewrite.
    9. For the Action Properties Rewrite URL type: \domain1\{R:1}
    10. Click on Append Query String.

    That should be it. Obviously domain1.com and domain1 are merely examples base on what you typed on this thread you will actually need to replace it with the correct domain name and subfolder name. Save the rule and try it out. It should redirect it to the subfolder but drop the subfolder name on the displaying URL on the browser.
     
  7. Thanks for the information. This is what the web.config file looks like (of course with domain1 replaced with my domain name). It still comes up with the folder in the URL. Let me know if you see anything strange. Also, I've applied this to the primary site. Do I need to go into the folder that the site files are located and put the rule in that folder?

    Thanks again for your help and fast response!

    <?xml version="1.0" encoding="UTF-8"?>
    <configuration>
    <system.webServer>
    <rewrite>
    <rules>
    <rule name="domain1">
    <match url="(.*)" />
    <conditions>
    <add input="{HTTP_HOST}" pattern="^domain1.com$" />
    <add input="{HTTP_HOST}" pattern="^www.domain1\.com$" />
    </conditions>
    <action type="Rewrite" url="\domain1\{R:1}" />
    </rule>
    </rules>
    </rewrite>
    </system.webServer>
    </configuration>
     
  8. Ray

    Ray

    Try adding this line in your conditions.

    <conditions logicalGrouping="MatchAny">
     
  9. Thank you so much! That did it! :)
     

Share This Page