How to rewrite subdirectory name in iis - regex

My website is located at:
example.com/NAME/home.aspx?id=1
I want to make it so this url works without redirecting to original:
example.com/DIFFERENTNAME/home.aspx?id=1
Also, when hitting the first url, I want it to be redirected to the 2nd.
I have url rewrite module Tried modifying several inbound rules, but cannot make it to work.

You can use HTTP Redirect and reference link follows
https://www.iis.net/configreference/system.webserver/httpredirect

Related

IIS 7.5 : URL Rewrite extension is Installed, but not shown (even after reboot)

In IIS version 7.5.7600.16385, I'm trying to redirect requests for example.com/* to www.example.com/*.
For example, if requests comes in like these:
http://example.com/ContactUS/
http://example.com/Donations/
I want IIS to redirect to these URLs:
http://www.example.com/ContactUS/
http://www.example.com/Donations/
So, as you can see, my goal is not to redirect all requests to the same static URL path. Instead, I'm trying to simply change the domain to the www subdomain while keeping the URL path intact for each redirect.
I've read articles that advise using an IIS extension called URL Rewrite.
However, when I try to install this extension the installer claims it is already installed, and even after a reboot, the URL Rewrite feature is not shown anywhere in IIS 7.5.7600.16385.
The only thing I can think of, that may be causing me not to see the URL Rewrite extension (in IIS), is that I do recall installing PHPManagerForIIS_V1.5.0.msi onto this same server several years ago. Maybe PHPManagerForIIS_V1.5.0 somehow overrides the URL Rewrite extension if you have it installed. I don't know.
Please advise if you know of a way I can accomplish my goal of dynamically redirecting all requests to their respective www canonical address, while keeping the URL path intact.

Regex - redirect from website.com to website.com/us and append substring

Can anyone help me correct my regex?
My hosting provides IP geolocation and I want to redirect US clients to another sub-directory of my website.
The website runs on a Nginx server and the hosting provides an interface where one can add redirection rules. The interface consists of Domain, Redirect from, Redirect To, Traffic from (country) and HTTP status code 301 or 302.
Example:
for all non-US clients website.com/blog/article/really-good-book
only for US clients website.com/us/blog/article/really-good-book
I currently have:
Redirect from ^/(?!us/)(.*)$
Redirect to /us/$1
This currently redirects me to website.com/us/index.php and nothing else. So the redirect is applied, it only appends index.php instead of blog/article/really-good-book.
Thank you for your help.
Eventually I found my own solution:
Redirect from ^(?!(/us|/index.php|/wp-admin|/wp-login.php))(.*)$
Redirect to /us/$1
I also added a rule for my wordpress backend, otherwise it would always redirect me back to website.com/us while trying to access website.com/us/wp-admin.

I need to redirect a vanity url to a page of the same name inside a directory

A typical .htaccess redirect looks like this:
RedirectMatch 301 /old-page /directory/new-page
I am trying to redirect only a specific, root level page (which doesnt exist), to a page with the same name, but in a different directory- and am getting a loop (because apache is seeing "oh that ends in /whatever, lets redirect it again). Here's my redirect example, does this have an obvious problem?
RedirectMatch 301 /specific-page-name /directory/specific-page-name
The purpose of this is to add a UTM code to a page when it gets typed in from some physical marketing media (flyer, card, etc) to give them an easy to type url, and get analytics that let us know that they are coming to the site from a specific non-web source.

Create a redirect rule for Azure CDN in Verizon which adds /index.html to the end of URL

I created an Azure CDN under Verizon Premium Subscription in the Azure portal with an endpoint which points to my Azure Static Website URL.
I want to create a redirect rule in Azure Verizon engine which adds /index.html to the end of URL if no extension is specified or the last sing of URL is not a / symbol.
So far I tried to use (.+\/[^\.]\w+$) regex expression, you can see an example of how it works here
My first approach:
In this case, if you type the URL https://blah.com/foo/bar in the web browser
it doesn't change the URL however you are able to view some of the content of the existing file from https://blah.com/foo/bar/index.html but some of the links to resources are broken. Not sure why I'm not getting the 404 in this case but maybe its because that I set the Index document name to index.html in the Static Website panel in the Storage account panel in Azure. If I open the Network tab in the developer tools of Chrome I can see a lot of 404 responses e.g.
And its because the website tries to get resources from the https://blah.com/foo/ directory instead of https://blah.com/foo/bar/
So, for example, the loadcsh.js in fact is located under the https://blah.com/foo/bar/loadcsh.js but the website is searching for the file under the wrong directory https://blah.com/foo/loadcsh.js
My second approach
In this case, if you type the URL https://blah.com/foo/bar
it makes a redirect to https://blah.com/foo/bar/foo/bar/index.html
so the foo/bar/ is redundant here.
My third approach
In this case, if you type the URL https://blah.com/foo/bar
it makes a redirect to https://blah.com/index.html
I have no idea how to apply the rule which makes a redirect from https://blah.com/foo/bar
to https://blah.com/foo/bar/index.html and is generic for all such cases.
Any ideas??
Cheers
I think your Regex expression is ok. You can add the rule URL redirect, in the Source textbox you type your Regex expression (.+\/[^\.]\w+$) and in the Destination textbox add https://%{host}/$1/index.htm. Here I used the HTTP variable for Azure CDN which can be used in Verizon. You can read more about the variables here.
In short words the %{host} returns a host name e.g. www.contoso.com
Please keep in mind all rule changes will require couple of hours propagation before it takes an effect on the CDN.

How to redirect traffic from one domain to another with Wordpress Redirection Plugin

I'm using the Wordpress Redirection Plugin on my site, and need to resolve a duplicate content issue by adding a 301 redirect from:
www.mysite.com
to:
www.mysite.org
NB: Both URLs share the same IP address, and the same content.
The redirect is currently working correctly for the root domain, but I also need to use a regular expression to ensure that all internal pages are also redirected to the same path on the new domain:
www.mysite.com/a-random-page/ --> www.mysite.org/a-random-page/
Any pointers appreciated.
Try using Regular Expression:
Source URL: http://www.example.com/(.*)
Target URL: http://www.example.org/$1
Check the Regular Expression Box.
This will redirect www.example.com/a-random-page/ to www.example.org/a-random-page/.