简体   繁体   中英

How to use URL Rewrite before HTTP Redirect on IIS

So I have a website running on IIS on an address like this: myserver.com/mysite . From here I made a rule to redirect the site to: myserver.com/mysite/path/to/file .

I did this using the HTTP redirection module to make a 302 redirect to path/to/file and that works fine.

The problem is that if I dont put the trailing slash / at the end of mysite I get a 404 error, so I used the built-in template AddTrailingSlashRule in the URL Rewrite module.

So if I disable the redirect, the trailing slash gets added at the end of the website just fine, but once I enable the HTTP redirect, it sends me to myserver.com/path/to/file/ and obviously that doesn't work, because I get the redirect first and then the rewrite.

Is there a way to change the "order" of the modules? Or is there a better way to achieve this?

Thanks for any help!

For anyone having this problem in the future, I ended up disabling the HTTP redirect and made a new rule using the URL Rewrite module.

It simply matches the ^$ regex and then redirects to path/to/file .

That rule goes after the trailing slash one so with or without the slash, it gets added and only then it gets redirected.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM