views:

68

answers:

1

Hi all,
I want add a rewrite rule to IIS 7 rewrite.
I want to redirect a user from page

http://localhost/myapp/register.html to http://localhost/myapp/register/register.html

And similar for other pages.

Any help?
Can I do the same using a rewrite action?

Using IIS7 and Windows Server 2008.

Thanks.

+1  A: 

I'm not sure if it suits your needs but you can try this one (and maybe make some small adjustments if the case):

<system.webServer>
    <rewrite>
        <rewriteMaps>
            <rewriteMap name="Register Redirect">
                <add key="register.html" value="/register/register.html" />
            </rewriteMap>
        </rewriteMaps>
        <rules>
            <rule name="Redirect rule1 for Register Redirect" stopProcessing="true">
                <match url="(.*)" />
                <conditions>
                    <add input="{URL}" pattern="^(.*)/register/(.*)(\.html)?$" negate="true" />
                </conditions>
                <action type="Redirect" url="{HOST}/register/{R:1}" appendQueryString="true" redirectType="Found" />
            </rule>
        </rules>
    </rewrite>
</system.webServer>
Padel
No.not working.now it is redirecting all pages to register directory. eg: if i do http://localhost/myapp/login.aspx it is now redirecting me to http://localhost/myapp/register/login.aspx.What i need is redirect only register.html request to /register/register.html
Amitd
I thought you were trying to move the entire application to a new location. In this case changing <add input="{URL}" pattern="^(.*)/register/(.*)(\.html)?$" negate="true" /> to <add input="{URL}" pattern="^((?:(?!/register/).)*)((^/register/)*)/register.html$" /> (so without negate="true" this time) should do the job. Hope this is what you were looking for.
Padel
seems to be working but now it is redirecting http://localhost/myapp/register.html to http://localhost/register/register.html .. can the redirect be made relative to application path i.e: http://localhost/myapp/register/register.html .
Amitd
I can't test this one but I think that the problem is here: <action type="Redirect" url="{HOST}/register/{R:1}" ...replace with <action type="Redirect" url="{C:1}/register/{R:1}" appendQueryString="true" redirectType="Found" />So replace {HOST} with {C:1}.
Padel
Now it works :) thx u very much for answer.
Amitd