I'm pretty new to all this so please be basic in your explanations.
The place I work just changed store software so I have a series of URLS that need massaging as Google, people, etc continue to use the old links.
The old links look like:
http://mydoman/usedateb.aspx?User_ID=38482&Category_ID=127
I know how to do a rewrite map to change
http://mydomain/usedateb.aspx?Category_ID=127
to
http://mydomain/hoopy-new-tour-name.aspx
And I know how to do a rewrite rule to remove the User_ID=xxx& from the Url.
My problem is in getting them both to work together. I need to take out the User_ID (since it's arbitrarily assigned) AND send it through the map to change to the hoopy-new-tour-name.
I have set up the rewrite rule to remove User at the top of the list and the rewrite map rule lower in the list but I end up at http://mydomain/usedateb.aspx?User_ID=38482&Category_ID=127
If it helps, my web.config has lines like
<add key="UseDateB.aspx?Category_ID=127" value="/success.htm" />
for the map and
<rule name="Remove extra parameters - UserID">
<match url="(.*)User_ID=([0-9]+&)(.*)" />
<conditions logicalGrouping="MatchAll" trackAllCaptures="false" />
<action type="Rewrite" url="{R:1}{R:3}" appendQueryString="false" />
</rule>
to strip the unwanted parameter.
The reason I need the map is that Cat 127 may be the hoopy tour but 128 may be the frood tour. There's a list of about 500 of these that need remapping but we gotta get the extra parameter off the incoming URLs for it to work.
All help appreciated! If I'm going about it completely wrong please let me know that too.
Look at this:
<rules>
<clear />
<rule name="RedirectToCategory" stopProcessing="true">
<match url="UseDateB.aspx" />
<conditions logicalGrouping="MatchAll" trackAllCaptures="false">
<add input="{QUERY_STRING}" pattern="Category_ID=127" />
</conditions>
<action type="Redirect" url="http://mydomain/hoopy-new-tour-name.aspx" />
</rule>
<rule name="RemoveUserID" stopProcessing="true">
<match url="(.*)" />
<conditions logicalGrouping="MatchAll" trackAllCaptures="false">
<add input="{QUERY_STRING}" pattern="(.*)(User_ID=[0-9]*)(.*)" />
</conditions>
<action type="Redirect" url="{R:0}?{C:1}{C:3}" appendQueryString="false" />
</rule>
</rules>
The first rule redirects based on category, and the second removes the User_ID. Try it and if you would like to do something else, state what is it.
Related
I have a problem with my URL rewrite and I don't know what I'm doing wrong so, maybe you can point me in the right direction. We had a intranet-site, which had a pattern like this: intranet.old-site.com. Now we got a new domain and I want to forward my outdated links to the front-page of our new intranet, which looks like: intranet.new-site.com.
I installed the URL Rewrite module in IIS and in my point of view, the setup is correct:
Match URL
Request URL: matches pattern.
Using: Wildcards
Pattern: *intranet.old-site*
Ignore case: true
Conditions
none
Server Variables
none
Action
Action Type: Rewrite
Action Properties: Rewrite-URL: http://intranet.new-site.com/
Append query string: true
Log rewritten URL: false
Stop processing of subsequent rules: false
I'm also open for any idea what might work, so if there is a rule for the web.config, I could try that as well.
Update 1:
the web-config looks like this now:
<rewrite>
<rules>
<rule name="RewriteSG2DE" patternSyntax="ECMAScript" stopProcessing="true">
<match url="(.*).sgbdd.saint-gobain(.*)" />
<action type="Redirect" url="intranet.stark-deutschland.net" />
<conditions logicalGrouping="MatchAny">
<add input="{HTTP_HOST}" pattern="(.*)sgbdd.saint-gobain(.*)" />
<add input="{HTTP_HOST}" pattern="intranet.sgbdd.saint-gobain.com" />
</conditions>
</rule>
</rules>
</rewrite>
I want any site, which is basically anything like intranet.sgbdd.saint-gobain.com/start.asp?something_more" to be forwarded / redirected to intranet.stark-deutschland.net/start.asp?something_more
For instance:
intranet.sgbdd.saint-gobain.com/start.asp?something_more --> intranet.stark-deutschland.net/start.asp?something_more
somesite.intranet.saint-gobain.com/my/new/site --> somesite.intranet.stark-deutschland.net/my/new/site
I also added conditions as suggested:
Thanks for you input
Using two URL rewrite rules is much easier to handle this.
If you want to redirect
intranet.sgbdd.saint-gobain.com/start.asp?something_more --> intranet.stark-deutschland.net/start.asp?something_more
somesite.intranet.saint-gobain.com/my/new/site --> somesite.intranet.stark-deutschland.net/my/new/site
Then rule can be like this.
<rule name="rule1" stopProcessing="true">
<match url="(.*)" />
<conditions trackAllCaptures="true">
<add input="{HTTP_HOST}" pattern="^(.*)saint-gobain.com$" />
<add input="{HTTP_HOST}" pattern="intranet.sgbdd.saint-gobain.com" negate="true" />
</conditions>
<action type="Redirect" url="http://{C:1}stark-deutschland.net/{R:1}" redirectType="Temporary" />
</rule>
<rule name="rule2" stopProcessing="true">
<match url="(.*)" />
<conditions>
<add input="{HTTP_HOST}" pattern="^intranet.sgbdd.saint-gobain.com$" />
</conditions>
<action type="Redirect" url="http://intranet.stark-deutschland.net/{R:1}" redirectType="Temporary" />
</rule>
I tried to combine two rules to one rule but there's something wrong with expression ?! so it is recommended to split into two rules.
If you means
intranet.sgbdd.saint-gobain.com/start.asp?something_more --> intranet.stark-deutschland.net/start.asp?something_more
somesite.intranet.sgbdd.saint-gobain.com/my/new/site --> somesite.intranet.stark-deutschland.net/my/new/site
Then the rule can be like this.
<rule name="RewriteSG2DE" patternSyntax="ECMAScript" stopProcessing="true">
<match url="(.*)" />
<action type="Redirect" url="http://{C:1}stark-deutschland.net/{R:1}" redirectType="Temporary" />
<conditions logicalGrouping="MatchAny">
<add input="{HTTP_HOST}" pattern="(.*)sgbdd.saint-gobain.com" />
</conditions>
</rule>
What I would like to do is if I have link:
http://www.test.com/photo.asp?hash=hfz6rhfgz&offset=10
to rewrite as:
http://www.test.com/photo/hfz6rhfgz/?offset=10
There can be other query parameters and hash may be on some other place than the first...
The problem is it would work, but as offset is the second parameter with my rule I get:
http://www.test.com/photo/hfz6rhfgz/&offset=10
That of course causes an error as I would need ? instead of &. In the redirected URL the offset is like second parameter and in the original link it is the second.
Here is my redirect rule:
<rule name="test-redirect" stopProcessing="true">
<match url="^photo.asp$" ignoreCase="true" />
<conditions logicalGrouping="MatchAll" trackAllCaptures="false">
<add input="{QUERY_STRING}" pattern="^(.*)hash=([\w]{8})(.*)$" />
</conditions>
<action type="Redirect" url="/photo/{C:2}/{C:1}{C:3}" redirectType="Permanent" appendQueryString="false" />
</rule>
I kind of find a solution by myself, but if there is something like
http://www.test.com/photo.asp?test=10&hash=jcekg876
It produces:
http://www.test.com/photo/jcekg876/?test=10&
so the last amp is too much, in other situations it works ok. If anybody knows how to get rid of this & it would be nice, because I need a clean URL redirect...
<rule name="test-redirect" stopProcessing="true">
<match url="^photo.asp$" ignoreCase="true" />
<conditions logicalGrouping="MatchAll" trackAllCaptures="false">
<add input="{QUERY_STRING}" pattern="(.*)hash=([\w]{16})[&]?(.*)" />
</conditions>
<action type="Redirect" url="/photo/{C:2}/?{C:1}{C:3}" redirectType="Found" appendQueryString="false" />
</rule>
I need to redirect all https requests to http, for example, if someone visits https://www.example.com/another-page/ to http://www.example.com/another-page/
I have the following rewrite rule in my web.config right now, but it's not working correctly. It's redirecting https://www.example.com/another-page/ to https://www.example.com/, so to the root of the site, but instead I want the redirect to stay in the same URL and only rewrite https to http.
<rule name="Redirect to HTTP" stopProcessing="true">
<match url="(.*)" />
<conditions>
<add input="{R:1}" pattern="^onepage/(.*)$" negate="true" />
<add input="{HTTPS}" pattern="^ON$" />
</conditions>
<action type="Redirect" url="http://{HTTP_HOST}/{R:0}" redirectType="Permanent" />
</rule>
Any help on changing the above rule so that it only changes https to http, but keeps the full url visited would be greatly appreciated!
I set up your rule, cleaned up a little, and it worked; so this isn't really answering with much new.
Suggestion: Remove the onepage input condition just for testing, as cheesmacfly suggested in the question comment.
Also, try changing the action to {R:1} instead of {R:0}. It shouldn't matter in this case, but I just like using 1 and up, to match the specific capturing group. R:0 means the entire matched string, which always confuses me just a little.
<rule name="Redirect to HTTP" stopProcessing="true">
<match url="(.*)" />
<conditions>
<add input="{HTTPS}" pattern="^ON$" />
</conditions>
<action type="Redirect" url="http://{HTTP_HOST}/{R:1}" redirectType="Permanent" />
</rule>
One possibility is that your browser has cached a previous attempt of your rules. When the redirectType is Permanent, and you're still developing or testing, the browser often caches a previous rule. Clear your browser cache, and/or remove the Permanent, and/or browse in incognito mode. When done testing, change it to permanent. See number 2 and 3 in this answer: https://stackoverflow.com/a/9204355/292060
Please paste the below code in web.config file.
<rule name="Redirect to http" stopProcessing="true">
<match url="(.*)" />
<conditions>
<add input="{HTTP}" pattern="off" ignoreCase="true" />
</conditions>
<action type="Redirect" url="http://{HTTPS_HOST}{REQUEST_URI}" redirectType="Permanent" appendQueryString="false" />
</rule>
I need to write a redirect to strip off parameters when a certain one exists, but I would like the redirect to be the same as the incoming url, just without the parameters. This is what I had and it doesn't work. I thought if I put the request URI in there without appending the querystring, then it would work but it results in a loop. Has anyone done this before?
<rule name="Remove parameters" stopProcessing="true">
<match url="(.*)" ignoreCase="true" />
<conditions trackAllCaptures="true">
<add input="{QUERY_STRING}" pattern="page=([0-9]+)" />
</conditions>
<action type="Redirect" url="{REQUEST_URI}" appendQueryString="false" />
The problem with jallen's answer is that the whole query string will be removed, which may not be ideal if you want to maintain certain parts of it. An alternative would be as follows:
<rule name="Remove paging parameters" stopProcessing="true">
<match url="(.*)?$" />
<conditions trackAllCaptures="true">
<add input="{QUERY_STRING}" pattern="(.*)(page=.+)(.*)" />
</conditions>
<action type="Redirect" url="{C:1}{C:3}" appendQueryString="false" />
</rule>
C:1 = Everything before the matching page parameter
C:2 = Is the
match itself, and what we want to exclude
C:3 = Everything after the
matching page parameter
Hence, we use the redirect {C:1}{C:3} to exclude only the page query string.
Got it with the following:
<rule name="Remove paging parameters" stopProcessing="true">
<match url="(.*)?$" />
<conditions trackAllCaptures="true">
<add input="{QUERY_STRING}" pattern="page=([0-9]+)" />
</conditions>
<action type="Redirect" url="{R:1}" appendQueryString="false" />
How can I redirect '/path?foo=abc&bar=def' to '/path/abc/def'?
I've tried the following:
<rule name="My rule" stopProcessing="false">
<match url="^path" />
<conditions>
<add input="{QUERY_STRING}" pattern="foo=/[^&]*/" />
<add input="{QUERY_STRING}" pattern="bar=(.*)" />
</conditions>
<action type="Redirect" url="/path/{C:0}/{C:1}" appendQueryString="false" />
</rule>
But this doesn't even process my match. Where am I going wrong?
I don't have access to a computer to verify this, but I think the following could simplify:
<rule name="Redirect old FAQ view" stopProcessing="false">
<match url="^path.*" />
<conditions>
<add input="{QUERY_STRING}" pattern="^foo=([^&]*).*?bar=(.*)" />
</conditions>
<action type="Redirect" url="/path/{C:0}/{C:1}" appendQueryString="false" />
</rule>
You don't need the second input line as you can use multiple capturing groups in one. I'm not sure if the whole line will come back as a match or not so you may need to adjust to {C:1}/{C:2}. Finally, I'm not sure if the match url was problematic. It would contain the query string as well, so that may have been causing it to miss. Look here for more details on the various components of the URL rewrite process.