I want to remove the index.cfm in the URL if there is there is no query_string e.g. www.mysite.com/index.cfm would be rewritten to www.mysite.com and 'www.mysite.com/Test/index.cfm would be rewritten to 'www.mysite.com/Test/ but if there is querstring in the url then url would not be affected e.g. 'www.mysite.com/Test/index.cfm?u=5 would not be affected by rewrite rule.
How can I get it?
This works perfect for me
<rule name="Default Document" stopProcessing="true">
<match url="(.*)index.cfm" />
<conditions logicalGrouping="MatchAll">
<add input="{REQUEST_METHOD}" pattern="^POST$" negate="true" />
<add input="{PATH_INFO}" pattern="^.*(/index.cfm/).*$" negate="true" />
<add input="{QUERY_STRING}" pattern=".+" ignoreCase="false" negate="true" />
</conditions>
<action type="Redirect" url="{R:1}" appendQueryString="true" redirectType="Permanent" />
</rule>
Related
i need to rewrite the url from old page to new page, an example:
old: https://www.mysite.it/scheda.asp?num=123456
new: https://www.mysite.it/scheda/?num=123456
i've put in web.config the following lines but don't work, when i go to https://www.mysite.it/scheda.asp?num=123456 noting happen, site go to the page without rewrite:
<rule name="scheda-rew" stopProcessing="true">
<match url="scheda.asp(.*)" />
<action type="Rewrite" url="scheda/{R:1}" logRewrittenUrl="true" />
</rule>
i try this:
<rule name="scheda-rew2" stopProcessing="true">
<match url="^scheda\.asp" ignoreCase="true" />
<conditions logicalGrouping="MatchAll" trackAllCaptures="false">
<add input="{QUERY_STRING}" pattern="isbn=([0-9]+)" />
</conditions>
<action type="Redirect" url="scheda/{C:1}" appendQueryString="false" />
</rule>
nothing appen, seem that all change i do haven't effect
You can try below rule, if you have any question please let me know:
<rule name="RewriteUserFriendlyURL2" stopProcessing="true">
<match url="^scheda.asp\?([^/]+)/?$" />
<conditions>
<add input="{REQUEST_FILENAME}" matchType="IsFile" negate="true" />
<add input="{REQUEST_FILENAME}" matchType="IsDirectory" negate="true" />
<add input="{REQUEST_URI}" pattern="^scheda/$" negate="true" />
</conditions>
<action type="Redirect" url="scheda/?num=123456" appendQueryString="false" />
</rule>
I have the following problem:
i want to let the users of an exact url redirect to another one.
Note: my URL immediately downloads a file.
What i want is to let the file forward to another file (it needs to download the file i'm redirecting to).
My Rule:
<rule name="File" patternSyntax="ExactMatch" stopProcessing="true">
<match url="https://SITE.be/download/DownloadFile?id=138999" />
<conditions logicalGrouping="MatchAny">
<add input="{URL}" pattern="https://SITE.be/download/DownloadFile?id=138999" />
<add input="{QUERY_STRING}" pattern="https://SITE.be/download/DownloadFile?id=138999" />
<add input="{REQUEST_FILENAME}" matchType="IsFile" />
</conditions>
<action type="Redirect" url="https://SITE.be/download/DownloadFile?id=138111" appendQueryString="false" />
</rule>
my rule isn't working, it doesn't redirect it and when i check 'URL redirect checkers' it mentions that there isn't a redirect set on the URL.
what am i doing wrong?
Edit:
I tried:
<rule name="File" stopProcessing="true">
<match url="download/DownloadFile?id=138999" />
<conditions logicalGrouping="MatchAny">
<add input="{HTTP_HOST}" pattern="^site.be$" />
</conditions>
<action type="Redirect" url="https://site.be/download/DownloadFile?id=138111" appendQueryString="false" />
</rule>
with no improving (redirect checkers on google still don't trigger that theres a redirect set)
According to your iis rewirte code, I find it has problem in match url part.
This part could only match the [download/DownloadFile] not the querystring.
If we want to check the query string id, we should use url rewrite condition.
More details, you could refer to below url rewrite rule.
<rule name="File" stopProcessing="true">
<match url="download/DownloadFile" />
<conditions logicalGrouping="MatchAll">
<add input="{QUERY_STRING}" pattern="id=138999" />
<add input="{HTTP_HOST}" pattern="^site.be$" />
</conditions>
<action type="Redirect" url="https://site.be/download/DownloadFile?id=138111" appendQueryString="false" />
</rule>
Or
<rule name="File" stopProcessing="true">
<match url="(.*)" />
<conditions logicalGrouping="MatchAll">
<add input="{HTTP_HOST}" pattern="sitebe" />
<add input="{REQUEST_URI}" pattern="download/DownloadFile\?id=138999" />
</conditions>
<action type="Redirect" url="https://site.be/download/DownloadFile?id=138111" appendQueryString="false" />
</rule>
I want to create a rule using IIS URL-Rewrite module. I want to redirect all pages from www.mydomain.com to mydomain.com
However, there are some pages on teh site that I do not like to have redirection. Those pages are
www.mydomain.com/mail/default.asp
www.mydomain.com/mail2/default.aspx
So here is my code so far
<rule name="Force non-WWW" enabled="true" stopProcessing="true">
<match url="(.*)" />
<conditions>
<add input="{HTTP_HOST}" pattern="^(www\.)(.*)$" />
<add input="{REQUEST_URI}" pattern="^/mail/(.*)" negate="true" />
<add input="{REQUEST_URI}" pattern="^/mail2/(.*)" negate="true" />
</conditions>
<action type="Redirect" url="https://{C:2}/{R:1}" />
</rule>
However, if I enable this rule and I go to www.mydomain.com/page, I got 500 error.
What is wrong with my code?
Just add condition <add input="{REQUEST_URI}" pattern="/some-url/(.*)" negate="true" />.You could use below rule:
<rule name="Force non-WWW" enabled="true" stopProcessing="true">
<match url="(.*)" />
<conditions logicalGrouping="MatchAll" trackAllCaptures="false">
<add input="{REQUEST_URI}" pattern="/mail/(.*)" negate="true" />
<add input="{HTTP_HOST}" pattern="(www\.)(.*)$" />
</conditions>
<action type="Redirect" url="http://{C:2}/{R:1}" appendQueryString="true" />
</rule>
Regards,
Jalpa.
I am having a hard time getting the below redirect rule to work...
<rules>
<rule name="Relative Path Rewrite" stopProcessing="false">
<match url=".*" />
<conditions logicalGrouping="MatchAll">
<add input="{REQUEST_FILENAME}" matchType="IsFile" negate="true" />
<add input="{REQUEST_FILENAME}" matchType="IsDirectory" negate="true" />
<add input="{REQUEST_URI}" pattern="^/$" negate="true" />
</conditions>
<action type="Rewrite" url="/" />
</rule>
<rule name="Ssl Redirect" stopProcessing="false">
<match url="(.*)" />
<conditions>
<add input="{HTTPS}" pattern="^OFF$" />
</conditions>
<action type="Redirect" url="https://{HTTP_HOST}/{R:1}" appendQueryString="true" redirectType="Permanent" />
</rule>
</rules>
The issue is as follows...
If i enter http://mywebsite.com it redirects to https://mywebsite.com no problem.
however, if i enter http://mywebsite.com/faq it is redirecting to https://mywebsite.com instead of https://mywebsite.com/faq and i cannot figure out why? It appears to be ignoring the '{R:1}' back reference that would come from my match which should be 'faq'
I've been battling with this for a while, any ideas on what is going on here would be great.
Some additional information is that i am hosting an angular 4.0 site that this rule is applied to...
Reversing the rules worked.
<rewrite>
<rules>
<rule name="Ssl Redirect" stopProcessing="false">
<match url="(.*)" />
<conditions>
<add input="{HTTPS}" pattern="^OFF$" />
</conditions>
<action type="Redirect" url="https://{HTTP_HOST}/{R:1}" appendQueryString="true" redirectType="Permanent" />
</rule>
<rule name="Relative Path Rewrite" stopProcessing="false">
<match url=".*" />
<conditions logicalGrouping="MatchAll">
<add input="{REQUEST_FILENAME}" matchType="IsFile" negate="true" />
<add input="{REQUEST_FILENAME}" matchType="IsDirectory" negate="true" />
<add input="{REQUEST_URI}" pattern="^/$" negate="true" />
</conditions>
<action type="Rewrite" url="/" />
</rule>
</rules>
</rewrite>
I Have some problems with redirecting to another URL based on the query string parameters.
I have url for mapping service, for example "http://www.mydomain.com/?lon=111&lat=222&zoom=3"
and I need it to be redirected to "http://www.mydomain.com/111/222/3".
I have this rule in my web.config, but it does not work
<rule name="Location redirect">
<match url="\?lon=(\d+)&lat=(\d+)&zoom=(\d+)" />
<action type="Redirect" url="{R:1}/{R:2}/{R:3}" redirectType="Found" />
</rule>
The reason is that URL does not include Query String, you ned to use conditions for that. If you use the User Interface, it includes a friendly URL template that will generate it for you.
Below you will find the Rewrite rule as well as the redirect so that legacy traffic (ugly URL) is redirected to the pretty URL:
<rule name="RedirectUserFriendlyURL1" stopProcessing="true">
<match url="^$" />
<conditions>
<add input="{REQUEST_METHOD}" pattern="^POST$" negate="true" />
<add input="{QUERY_STRING}" pattern="^lon=([^=&]+)&lat=([^=&]+)&zoom=([^=&]+)$" />
</conditions>
<action type="Redirect" url="/{C:1}/{C:2}/{C:3}" appendQueryString="false" />
</rule>
<rule name="RewriteUserFriendlyURL1" stopProcessing="true">
<match url="^/([^/]+)/([^/]+)/([^/]+)/?$" />
<conditions>
<add input="{REQUEST_FILENAME}" matchType="IsFile" negate="true" />
<add input="{REQUEST_FILENAME}" matchType="IsDirectory" negate="true" />
</conditions>
<action type="Rewrite" url="?lon={R:1}&lat={R:2}&zoom={R:3}" />
</rule>