How to rewrite URL in IIS using regex - regex

I have IIS and want to configure URL rewriting.
How I can to rewrite any type of URL like:
http://anydomain.com/subfolder/page.html
to
http://anydomain.com/mysubfolder/subfolder/page.html
So only what I need is to add just one subfolder name into URL after host name.

Regex for split url
^(https?:\/\/[^\/]*\/)(.*)$
and How-To iis url rewrite. Your pattern must look like that
{R:1}mysubfolder/{R:2}

Related

Remove from URL haproxy

I have an haproxy server and I need it to rewrite the URL.
For example, I have a url that is like this:
http://myserver.com/UserName/signalr/.....
and I need to remove the UserName, so when haproxy forwards to the server the url becomes:
http://myserver.com/signalr/.....
if I know the UserName then this works:
reqrep ^([^\ ]*\ /)UserName[/]?(.*) \1\2
My problem is that the UserName is not a static, but always in the same place in the URL, directly after the domain.
Any help appreciated.
Use the regex http:\/\/myserver.com\/(\w+) to determine the username directly after the domain. The first captured group is the username.
I did find a solution to this if anyone is interested
reqrep ^([^)((?:[^\/]*\/){1}[^\/]*\/(.*) \1\2

Get Complete String after specific word using regex

I want to redirect 1000 of URL'S using wordpress Redirection plugin with regex.
Here is the my URL
http://domain.com/blog/tag/washington/
need to redirect on
http://domain.com/tag/washington/

IIS7 URL Rewrite with Regex

I'm trying to do a URL rewrite when a user accesses a certain URL of my site:
Accessed URL: https://client1.domain.com
Rewritten URL: https://new-client1.otherdomain.com
My site has many URLs that point to it, so the simple HTTP redirect module will not be a valid solution for this. What would the Regex be and what would I want to fill in for each section in a rewrite rule?
Thanks
Try this:
s/client1.domain/new-client1.otherdomain/g
You can use this regex pattern to search for client1.domain in order to replace it:
(?<=//)([^.]+)\.domain
Replace it with a backreference to client1 and the new domain like so:
$1\.otherdomain

how to convert sub-domain URL to domain URL using smarty

I have a URL like this
http://subdomain.domain.com/xyz-200_some_information
I want to convert this URL to following URL using smarty.
http://www.domain.com/xyz-200_some_information
That is, need to replace subdomain with www
subdomain is not fixed, there may be more more subdomains. I'm looking for a smarty based solution instead of a PHP one, as I don't have to acc change
You can use a regex_replace
{$var|regex_replace:"/http:\/\/.*?\./":"http://www."}
This matches a region from http:// to the first dot and replaces it with http://www.

IIS7 URL Rewrite Regular Expression

I am trying to set up IIS7 so the a URL with the pattern:
www.test.com/docs/ADocument.pdf
will get redirected to the URL
www.test.com/1.0/docs/ADocument.pdf
I am having trouble with the regular expression. The pattern should work with any page at the end of the url.
Rewrite this...
^(docs/.*)$
to this...
1.0/{R:1}