IIS7 URL Rewrite with Regex - 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

Related

In Nginx, how to match and entire URL and Query String and redirect to a URL and Query String

I have been searching for a while now, trying work arounds and haven't come up with anything useful.
I have a (large) list of URL's from an site migration and need to match the entire URL + Query String and redirect to another URL.
As far as I can see the following only matches /mens, but not the rest of the query string.
rewrite "^/mens?brand%5B%5D=27&section%5B%5D=5&price-min=0&price-max=2000&sort=newest" "/t/gender/men" permanent;
The reason it's important is that I have a bunch of similar URL's with slightly different Query Strings, which need to be redirected, similar to below, but actually work.... :-/
rewrite "^/mens/shop?q=road+map+polo" "/t/category/golf-knits" permanent;
rewrite "^/mens/shop?q=six+pocket+pant" "/t/category/golf-pants" permanent;
#etc... ad noiseam
Thanks in advance,
Paul.
The $request_uri variable contains the entire URL. You could use a map to translate it into a redirection.
map $request_uri $target {
~*^/mens/shop\?q=road\+map\+polo /t/category/golf-knits;
~*^/mens/shop\?q=six\+pocket\+pant /t/category/golf-pants;
}
server {
...
if ($target) { return 301 $target; }
...
}
See this document for details.

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}

Apache URL rewrite (mod_rewrite) and uuid

I want to rewrite the following URL in apache:
abc.php?id=1234&token=xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx
where xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx is a V4 UUID
I have tried to make rewrite rule like:
RewriteRule ^/ABC/([0-9]+)$/^([0-9a-fA-F]){8}-([0-9a-fA-F]){4}-([0-9a-fA-F]){4}-([0-9a-fA-F]){4}-([0-9a-fA-F]){12}.([0-1]){1}/ /abc.php?id=$1&token=$2
but it seems that it's not really working.
I think i dun need a regex that exactly represent a V4 UUID but just simple regex to represent the Characters and hyphen in the UUID string, anybody has good idea in apache regex?
This is what you want:
RewriteRule ^/ABC/([0-9]+)/([a-zA-Z0-9\-]+)$ abc.php?id=$1&token=$2
If you want to further validate the token, it would be better to do so in PHP, seeing as that's its intended use.

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}