Remove from URL haproxy - regex

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

Related

Redirect Regex for URLs

I have a Wordpress site and I'd like to redirect traffic based on specific criteria. I'm using a redirect plugin that has a Source URL (which can be a regex) and a Destination URL that can contain the result from the regex such as $1.
/blog/{slug} should redirect to /{slug} but only when {slug} is not ?page= or page/{anything}
So /blog/the-article-name will redirect to /the-article-name but /blog/?page=3 will not redirect and /blog/page/3 will not redirect.
Also, /blog/category/{slug} should redirect to /{slug}.
Thanks
I was able to figure it out after some trial and error:
^/blog\/(?!.*(page\/.*|\?paged=))+(.+)
I can access the 2nd match (the slug) using /$2
https://example.com/blog/the-article-slug will match for group 2 and redirect to https://example.com/the-article-slug
https://example.com/blog/page/2 will not match for group 2
https://example.com/blog/?paged=2 will not match for group 2
I'm using another redirect rule, ^/blog/category/(.*) to match the slug which I can access using /$1
https://example.com/blog/category/the-article-slug will match for group 1 and redirect to https://example.com/the-article-slug
Hope this helps someone else

regex pattern for url validation to make http as required

I'm stuck at regex pattern.
Currently I'm using regex:
https?:\/\/(?:www\.|(?!www))[^\s\.]+\.[^\s]{2,}|www\.[^\s]+\.[^\s]{2,}
but it takes www.google.co.in as a valid url but I want http:// or https:// as a required part of url.
Is there any way I can achieve that?

How to rewrite URL in IIS using 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}

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.