0

Please, I have this folder:

root/teste_seo/script.asp

Instead to use the url:

www.mysite.com/teste_seo/script.asp

I need this url using IIS rewrite:

www.mysite.com/script.asp

I try to use the rule from this link but didn't work:

IIS 7.5 URL Rewrite - Rewrite a Folder from an URL

Please, how can I write this rule?

PS.: For any *.asp file inside teste_seo folder.

Ailton
  • 165
  • 1
  • 12

1 Answers1

0

The following rule should do the trick:

<rule name="teste_seo" stopProcessing="true">
    <match url="^script.asp" />
    <action type="Rewrite" url="/teste_seo/script.asp" />
</rule>

Then just link to the www.mysite.com/script.asp

Edited after comment from OP:

If so you can use the following rule as long as you have a copy of the script files in the root of your document:

<rule name="teste_seo" stopProcessing="true">
    <match url="^teste_seo/([^\.]+\.asp)" />
    <action type="Redirect" url="/{R:1}" />
</rule>

And if you need all script files to point to the same one you can use:

<rule name="teste_seo" stopProcessing="true">
    <match url="^teste_seo/([^\.]+\.asp)" />
    <action type="Redirect" url="/script.asp" />
</rule>

Edited again after clarification:

These 2 rules should then be the fix you need:

<rule name="teste_seo_redirect" stopProcessing="true">
    <match url="^teste_seo/([^\.]+\.asp)" />
    <action type="Redirect" url="/{R:1}" />
</rule>
<rule name="teste_seo_rewrite" stopProcessing="true">
    <match url="^([^\.]+\.asp)" />
    <action type="Rewrite" url="/teste_seo/{R:1}" />
</rule>
Siggi2k
  • 71
  • 4
  • Hi Siggi2k! Tks! Sorry but I forget to write that I need for any *.asp file inside teste_seo folder. From abc.asp to xyz.asp. – Ailton May 30 '17 at 12:57
  • Do you need all scripts that are in the teste_seo folder to work on the root level? Do you need www.mysite.com/teste_seo/script.asp to point to www.mysite.com/script.asp and then www.mysite.com/teste_seo/another-script.asp to point to www.mysite.com/another-script.asp? I Edited my original answer with the code that i think will help you, so please mark it as an answer if this solved your problem. – Siggi2k May 31 '17 at 09:51
  • Yes, you are correct. But, I need to have the copy of all files inside teste_seo folder in root folder? You said "as long as you have a copy of the script files in the root" – Ailton May 31 '17 at 12:19
  • I see, i misunderstood, but i have edited my answer with what i think will be your solution. – Siggi2k May 31 '17 at 13:30
  • 1
    Thank you my friend! Tha's exactly what I was looking for. – Ailton May 31 '17 at 22:48