简体   繁体   中英

IIS 8.5 URL rewrite with Regex doesn't work

I want to rewrite all user URL requests from

_http://localhost:5678/dir/index.html

to

_http://localhost:5678/subdir/dir/index.html

In my ISS URL rewrite module rules I use this pattern: ^(https?://[^/] [:0-9] /)(.*)$

using this pattern URL address divided into two parts: host-name and directory with page or any other content. In IIS action properties Redirect URL field I write: {R:1}subdir/{R:2}

I think that this rule should redirect all requests from

_http://host-name/page.html

to

_http://host-name/subdir/page.html

but this is not work. Changing Action type from Rewrite to Redirect doesn't work to. When in Redirect URL field I write direct URL to resources (for example, _http://localhost:5678/subdir/dir/index.html) IIS trying to redirect me to that URL but browser (Firefox and Chrome) throw an exception ERR_TOO_MANY_REDIRECTS. How I can to configure IIS URL rewrite action properly?

Use this pattern instead since you don't have to match the entire pattern to accomplish this. ^(/dir)(/.*)?

then the redirect URL should look like

{HTTP_HOST}/subdir/{R:1}{R:2}

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