How to set up a rewrite rule for an ASP site? - url-rewriting

I would like to redirect any photo.asp?id= here is anything after the =
to photographe.asp?id= here is anything after the =
example
photo.asp?id=161#photographie-automobile
to
photographe.asp?id=161#photographie-automobile
or
photo.asp?id=230#road-suv
to
photographe.asp?id=230#road-suv
Code below:
<rule name="SpecificRedirect" stopProcessing="true">
<match url="^photo.asp$" />
<action type="Redirect" url="/photographe.asp$"
redirectType="Permanent" />
</rule>

Related

iis7.5, web.config how to redirect not exist file(page) to another page?

I'm using iis-7.5 and web.config file.
I want to redirect "somepage.asp?id=63" to "somepage/10.html".
My web.config is like this:
<?xml version="1.0" encoding="UTF-8"?>
<configuration>
<system.webServer>
<rewrite>
<rules>
<rule name="301 Redirect 2" stopProcessing="true">
<match url="somepage.asp?id=63" />
<action type="Redirect" url="somepage/10.html" redirectType="Permanent" />
</rule>
</rules>
</rewrite>
</system.webServer>
</configuration>
it didn't work, when I change <match url="somepage.asp?id=63" /> to <match url="somepage.asp" />, (delete ?id=63) , it worked, why? how can i do?
As far as I know, the url rewrite match url pattern doesn't match query string.
If you want to redirect the url according to the query string, I suggest you could try to use condition.
More details, you could refer to below url rewrite rule:
<rule name="Redirect according to query string" stopProcessing="true">
<match url="somepage.asp" />
<conditions>
<add input="{QUERY_STRING}" pattern="id=63" />
</conditions>
<action type="Redirect" url="somepage/10.html" appendQueryString="false" />
</rule>

IIS 7 Url Rewrite Rule

I want to rewrite an existing url /rss/content.aspx?id=4878 to display as /rss.
I also need requests to /rss to display this same content. I have this rule:
<rule name="ContentRSS">
<match url="^rss$" />
<action type="Rewrite" url="rss/content.aspx?id=4878" />
</rule>
but it doesn't rewrite requests to rss/content.aspx?id=4878 as /rss
You rule should be:
<rules>
<rule name="ContentRSS redirect" stopProcessing="true">
<match url="^rss/content.aspx$" />
<action type="Redirect" url="/rss" appendQueryString="false" />
<conditions>
<add input="{QUERY_STRING}" pattern="id=4878" />
</conditions>
</rule>
<rule name="ContentRSS rrewrite">
<match url="^rss$" />
<action type="Rewrite" url="/rss/content.aspx?id=4878" />
</rule>
</rules>
This rule will rewrite /rss to /rss/content.aspx?id=4878. And when you will try to open in browser rss/content.aspx?id=4878 it will redirect to /rss

301 redirect rule in web.config

I have a url http://example.com/abc/pqr/112-digital I want do 301 redirect to http://example.com/abc/pqr/digital
not working..
<rule name="RedirectToBlog140" stopProcessing="true">
<match url="^abc/pqr/112-digital?$|^abc/pqr/112-digital(.*)$" />
<conditions />
<serverVariables />
<action type="Redirect" url="abc/pqr/digital/{R:1}" />
</rule>
Please Help

Subdomain url-rewrite in web.config

This is how i currently want to redirect my site to
when i try navigating to
http://sub1.sitename.com it should redirect to sitename.com/newprojects/sub1
and the same for sub2
i tried using it like this but it ends up loading www.sitename.com
<rewrite>
<rules>
<rule name="Redirect" stopProcessing="true">
<match url="^sub1\.sitename\.com$" ignoreCase="true" />
<action type="Redirect" url="sitename\.com/newprojects/sub1/" redirectType="Permanent" />
</rule>
<rule name="Redirect1" stopProcessing="true">
<match url="^sub2\.sitename\.com$" ignoreCase="true" />
<action type="Redirect" url="sitename\.com/newprojects/sub2/" redirectType="Permanent" /> </rule>
</rules>
</rewrite>
You could try matching all the URL's and then filtering based on what you want to redirect.
<rewrite>
<rules>
<rule name="sub1 redirect" stopProcessing="true">
<match url="(.*)" />
<conditions>
<add input="{HTTP_HOST}" pattern="^sub1\.site\.com(/)?$"/>
<add input="{PATH_INFO}" pattern="^/newprojects/sub1/" negate="true" />
</conditions>
<action type="Rewrite" url="\newprojects\sub1\{R:0}" />
</rule>
</rules>
</rewrite>
this worked for me.

IIS7 URL rewrite error

This is my url: http://www.domain.com/advertenties/advertentie-delen/?id=23&t=1&url=ad-placed-for-simons-company-by-me
With the rewrite rule below I get this error: "The page cannot be displayed because an internal server error has occurred"
<rule name="share ad">
<match url="^advertenties/advertentie-delen?/?$" />
<action type="Rewrite" url="share_email.aspx?id={R:1}" appendQueryString="true" />
</rule>
Found it. It says this "id={R:1}",which means it expects a variable on the match url tag. Since there was no variable it throws an error, this is what I have now:
<rule name="share ad">
<match url="^advertenties/advertentie-delen?/?$" />
<action type="Rewrite" url="share_email.aspx" appendQueryString="true" />
</rule>

Resources