how to remove # from url URL rewrite - iis

Our url has # in our program, how do we hide it from user
example: www.example.com/#/privacypolicy
need to change that to www.example.com/privacypolicy
is where any way to achive this using webconfig

URL won't send any part to server after #, that means server won't get part of privacypolicy,so use url.encode is a great way to make complete url send to server.
Hash Tags in the URL serve a special purpose to the client browser, not to the server.so Browser did not anything after the '#' character.
<rule name="#" enabled="true" stopProcessing="true">
<match url=".*" />
<conditions logicalGrouping="MatchAll" trackAllCaptures="false">
<add input="{REQUEST_URI}" pattern="(.+)" />
</conditions>
<action type="Rewrite" url="http://www.example.com/{UrlEncode:{C:1}}" />
This will make www.example.com/#/privacypolicy become www.example.com/%2F#/privacypolicy, so that server can get privacypolicy.

Related

Show default document extension in URL

I've been given several requests to rewrite a URL in IIS. One of them includes having the .html page as part of the URL, but without the HTML tag. For example, www.foo.com/bar.html would be displayed as www.foo.com/bar instead. I have this rule to accomplish that and it seems to work ok.
<rule name="Hide .html ext" enabled="true">
<match url="^(.*)" ignoreCase="false" />
<conditions logicalGrouping="MatchAll" trackAllCaptures="false">
<add input="{REQUEST_FILENAME}" matchType="IsFile" negate="true" />
<add input="{REQUEST_FILENAME}" matchType="IsDirectory" negate="true" />
<add input="{REQUEST_FILENAME}.html" matchType="IsFile" />
</conditions>
<action type="Rewrite" url="{R:0}.html" />
</rule>
The problem I'm having is that since index.html is a default document in IIS, so www.foo.com never shows index.html for my html rewrite rule to handle it (at least that is my assumption as to what is happening). This is the same if the page is something like www.foo.com/bar/index.html. They would want www.foo.com/bar to redirect to www.foo.com/bar/index in the URL.
Essentially is it possible to somehow force the default document to show? I've been attempting all sorts of strange scenarios using {PATH_INFO}, {URL}, and {PATH_TRANSLATED} to somehow attempt to catch any index.html page to rewrite it "correctly" in the URL.
Example attempt that I know is in the wrong direction:
<rule name="Include /index" stopProcessing="true">
<match url="(.*)" />
<conditions logicalGrouping="MatchAll" trackAllCaptures="false">
<add input="{PATH_INFO}" pattern="(.+?(?=(index.html|\/index.html|\/index.html\/)$)|^(index.html))" />
<add input="{URL}" pattern="(.+?(?=(index|\/index|\/index\/)$)|^((index)|(\/index\/)))" negate="true" />
</conditions>
<action type="Redirect" url="/index" appendQueryString="false" redirectType="Permanent" />
</rule>
I feel like I'm overthinking this and there's possibly a simpler solution that uses IIS URL rewrite.
If the default document function is enabled, the index cannot be displayed in the URL, including index.html.
If you want to display the index in the url unless manually enter it in the browser. There are some problems with URL rewriting. Even if the URI is empty, the request is sent to IIS, and what is received in IIS is the URL with farvicon.ico attached. In URL rewriting, it is not very accurate to determine whether the URI is empty.

IIS 8 - Domain and URL rewrite

I am trying to rewrite domain and URL of request so when user goes to URL:
http://somedomain.com/
he sees content of:
https://serverdomain.com/applications/somedomain/
Of course, anything that is appended to somedomain.com/ should also be appended to applications/somedomain/
I installed ARR 3 and Failed Request Logging, but I can't get to this result. Moreover, after installing ARR, 404 errors start throwing 502.2.
The best rule I got was:
<rule name="test-domain" stopProcessing="true">
<match url=".*" />
<conditions logicalGrouping="MatchAll" trackAllCaptures="false">
<add input="{HTTP_HOST}" pattern="somedomain.com" />
</conditions>
<action type="Rewrite" url="https://serverdomain.com/applications/somedomain{R:0}" logRewrittenUrl="true" />
</rule>
It almost works, but I don't know why it takes me to home page (e.g. https://serverdomain.com/).
When I set action type to Redirect it looks OK, but I need this rewrited, so user sees original URL.

How do I create a redirect URL in IIS 7.5

I'm new to the world of IIS in terms of redirects and have been tasked with setting up a redirect for a portion of our site.
The URL I need to redirect is brandview.auditedmedia.com and I need it
to go to https://auditedmedia.com/data/media-intelligence-center/brand-view
The trick is we can have a URL with a QueryString such as
brandview.auditedmedia.com/memberNumber=423524 and that URL should NOT
be redirected.
Also, the scheme of brandview.auditedmedia.com does not matter. Both
HTTP and HTTPS should redirect.
So I'm not sure should I be doing this in IIS or as a RouteMap in the app?
If I should be doing this in IIS can someone point me to either an article or give an example of what I need to do?
Thanks
Bob
You need to add URL rewrite rule on the server level. Use conditions to prevent redirection for requests with non-empty query string string.
For your case it is necessary to add the following rule:
<rule name="brandview redirect" stopProcessing="true">
<match url=".*" ignoreCase="true" negate="false" />
<conditions logicalGrouping="MatchAll">
<add input="{HTTP_HOST}" pattern="^brandview\.auditedmedia\.com$" negate="false" />
<add input="{QUERY_STRING}" pattern=".+" negate="true" />
</conditions>
<action type="Redirect" url="https://auditedmedia.com/data/media-intelligence-center/brand-view" appendQueryString="false" redirectType="Permanent" />
</rule>
There is detailed instruction on your question. Note, the rule must be created in system.webServer/rewrite/globalRules section of %windir%\system32\inetsrv\config\ApplicationHost.config file.
I got the pattern fixed (see below) and though all the pattern matching works properly in URL Rewrite Module (using test button and putting in different URLs), it still isn't working properly when I attempt to go to the site. The server just continues with serving the page and not redirecting.
<rewrite>
<globalRules>
<rule name="brandview redirect" stopProcessing="true">
<match url=".*" ignoreCase="true" negate="false" />
<conditions logicalGrouping="MatchAll">
<add input="{HTTP_HOST}" pattern="^(https?:\/\/)?brandviewdev\.auditedmedia\.com$" negate="false" />
<add input="{QUERY_STRING}" pattern=".+" negate="true" />
</conditions>
<action type="Redirect" url="https://auditedmedia.com/data/media-intelligence-center/brand-view" redirectType="Permanent" appendQueryString="false" />
</rule>
</globalRules>
</rewrite>
Also you can add URL rewrite rule using GUI. Before you start make sure that both of the direct HTTP-requests to brandview.auditedmedia.com and https://auditedmedia.com/data/media-intelligence-center/brand-view returns status 200 (OK).
Open IIS Manager by prompting inetmgr command.
Select brandview web site in the Connections pane and open URL Rewriting feature.
Create new empty rule using Add rule(s)... action.
Within the Edit Inbound Rule dialog, enter the following:
Name: Redirect to auditedmedia.com;
Requested URL: Matches the Pattern;
Using: Regular expressions;
Pattern: .*;
Action type: Redirect;
Redirect URL: https://auditedmedia.com/data/media-intelligence-center/brand-view.
Append query string: false;
Redirect type: See Other (303);
Save the rule by clicking Apply on the Actions pane.
Make sure that request to brandview.auditedmedia.com will be redirected to https://auditedmedia.com/data/media-intelligence-center/brand-view.
Repeat steps 1, 2 and select Redirect to auditedmedia.com rule.
Execute action Add condition(s)... with following:
Condition input: {QUERY_STRING};
Check if input string: Does Not Matches the Pattern;
Pattern: .+;
Ignore case: true.
Push OK button.
As result, all requests to brandview.auditedmedia.com with empty query string will be redirected to https://auditedmedia.com/data/media-intelligence-center/brand-view page. After testing you can change redirect type to 301.
After trying different combinations I finally got the redirect to work correctly and to be honest, I'm not sure how. Here is my config
<rewrite>
<rules>
<rule name="Brandview Redirect" enabled="true" stopProcessing="true">
<match url="^$" ignoreCase="true" negate="false" />
<action type="Redirect" url="https://auditedmedia.com/data/media-intelligence-center/brand-view" appendQueryString="false" redirectType="Temporary" />
<conditions>
<add input="{HTTP_HOST}" pattern="brandviewdev\.auditedmedia\.com" />
<add input="{QUERY_STRING}" pattern=".+" negate="true" />
</conditions>
</rule>
</rules>
</rewrite>

Url redirect on azure

I have used web.config to redirect the url to a different website but after i remmove the line of code that redirects, the changes do not reflect and when i access the website i still get an redirect.
I have tried to restart the AppService plan but that does not work.
How can I change everything back as it was?
the code below i have written:
<rule name="[RULE NAME]" stopProcessing="true">
<match url="(.*)" />
<conditions logicalGrouping="MatchAny" trackAllCaptures="false">
<add input="{HTTP_HOST}{REQUEST_URI}" pattern="[OLD URL]" />
<add input="{HTTP_HOST}{REQUEST_URI}" pattern="www.[OLD URL]" />
</conditions>
<action type="Redirect" url="http://[NEW URL]" redirectType="Permanent"/>
</rule>
You had a Permanent redirect. That will result in a HTTP 301 code, which in most normal circumstances will be cached.
It may help to clear your browser's cache. Or try a different browser.
See How long do browsers cache HTTP 301s?.

Redirect *azurewebsites.net to .com but not for CDN

I have a Joomla site on Azure. I have set up the .com properly and I understand why the *azurewebsites.net URL is still working.
I wanted to redirect all traffic from *azurewebsites.net to the .com. I followed this guide and it works as intended.
http://onthecloud.azurewebsites.net/seo-tip-how-to-block-the-.azurewebsites.net-domain
However, I also have an Azure CDN in place (mycdn.azureedge.net/). I use JCH Optimize to set up the CDN. I see the the calls to mycdn.azureedge.net/ are generated properly. However, somehow, because of the web.config redirect, all the traffic is redirected from the CDN back to my .com, which defeats the purpose of the CDN. This creates a lot of redirect calls.
Is there a way to write the web.config lines to exclude the CDN?
Here's what my web.config looks like. When I delete those lines, the CDN redirects disappear, so the problem is really here.
<rule name="Disable Azure Domain" patternSyntax="Wildcard" stopProcessing="true">
<match url="*" />
<conditions logicalGrouping="MatchAll" trackAllCaptures="false">
<add input="{HTTP_HOST}" pattern="*.azurewebsites.net" />
</conditions>
<action type="Redirect" url="http://www.example.com{REQUEST_URI}" redirectType="Permanent" />
</rule>
Look at your conditions. You're filtering all traffic that goes to "*.azurewebsites.net". All calls to your cdn fall into that filter as well, which is why you're seeing them be redirected:
<conditions logicalGrouping="MatchAll" trackAllCaptures="false">
<add input="{HTTP_HOST}" pattern="*.azurewebsites.net" />
</conditions>
Instead, filter the calls just to your website. So your condition would look more like:
<conditions logicalGrouping="MatchAll" trackAllCaptures="false">
<add input="{HTTP_HOST}" pattern="yoursite.azurewebsites.net" />
</conditions>
That'll let calls to the CDN go through just fine.
You can find more details on setting up redirect rules for your Azure Web App here: http://zainrizvi.io/2016/04/07/block-default-azure-websites-domain/
Fyi, below is the full web.config that I use for my site. You'll not that I've set some of the other settings a bit differently. Try using that web.config file instead (just change the site names as appropriate) and see if it works for you.
<configuration>
<system.webServer>
<rewrite>
<rules>
<rule name="Redirect to zainriziv.io" stopProcessing="true">
<match url="(.*)" />
<conditions logicalGrouping="MatchAny">
<add input="{HTTP_HOST}" pattern="^zainrizvi\.azurewebsites\.net$" />
</conditions>
<action type="Redirect" url="http://www.zainrizvi.io/{R:0}" />
</rule>
</rules>
</rewrite>
</system.webServer>
</configuration>
Note: When you're testing the fix your browser might have cached the redirect, so you might want to try fiddler or a new browser/pc to verify things work as expected

Resources