Have a .net webapp running on IIS.
I have run across something I haven't had to really deal with before. we have partners or clients that have their own "pages" on our domain. currently the URL is www.mydomain.com/?code=partnercode, but for ease of use on business cards and such they want it to be more like www.mydomain.com/partnername and I am not sure how to do this.
I know we can do something like the following in the htaccess in Apache
RewriteRule ^partnername$ index.php?code=partnerid [L]
I am wondering if there is some way to do this in the web.config? there has got to be something, but I am unsure where to look to find it. I have tried those online htaccess to web.config code converters and it failed miserably. The other thing is I would prefer to not have to change the partnerID that we already have in the DB.
I found this on another question on this site but I don't think it will do what I need it to. It will change the URL in the browser one the user hits the page but I also want it to be accessible using the www.mydomain.com/partnername URL as well.
if ( $_SERVER['REQUEST_URI'] == '/index.php?code=partnerid') {
echo '<script type="text/javascript">window.history.pushState("", "", "/partnername");</script>';
}
IIS has extension that partially supports your scenario, it is called URL Rewrite.
I said partially, because you can use it to rewrite URLs from www.mydomain.com/partnername to www.mydomain.com/?code=partnername. What it doesn't support (at least I don't think it does) is mapping a partner name to partner code (unless you have small number of partners and you can add rewrite rule for every partner).
And here is an article showing a fraction of what you can do with URL Rewrite.
In your case if you want to rewrite www.mydomain.com/partnername to www.mydomain.com/?code=partnername, your rule configuration could look something like this (not tested on IIS):
<rewrite>
<rules>
<rule name="Rewrite to query string">
<!-- I'm using hardcoded text, but it is regular expression and you can
write very advanced conditions -->
<match url="^(partner)" />
<!-- changes incoming url /partner to ?code=partner -->
<action type="Rewrite" url="?code={R:1}" />
</rule>
</rules>
</rewrite>
Related
I'm new to the IIS URL Rewrite tool and need some help with my configuration (http://www.iis.net/downloads/microsoft/url-rewrite):
I need to redirect all the old product links from an old shop system (using .html links) to our new shop system (using a longer path and .aspx links).
The old URLs are built like this: www.domain.com/[product number].html
I need them like this: www.domain.com/path1/path2/[same product number].aspx
path1 and path2 are fixed, they don't change at all.
I tried lots of different tips (from google and also from stackoverflow), this is what came out (but did not work - I get the new URL, but the product number is empty):
<rule name="HTML zu ASPX" stopProcessing="true">
<match url="([_0-9a-z-]+)\.html" />
<action type="Redirect" url="path1/path2/{R:1}.aspx" />
Any ideas? Any questions I forgot/didn't know to be asked?
Thanks in advance
Daniel
Make sure browser is not caching results (Redirects are cached and always little bit hard to invalidate)
I wrote a redirect rule that will route client's content requests, to the linked Azure CDN serving my hosted ASP.Net MVC website on an Standard plan.
I tried several iteration of the rule; nothing is working
These are the steps I took to implementation
Create Storage
Create CDN ENDPOINT http:// azxxxxxx.vo.msecnd.net/
Created a subdomain at GoDaddy verified and pointing to azxxxxxx.vo.msecnd.net/
Created a public container using Cloudberry Explorer
Uploaded images blobs to the container and
Tested content availability successfully on the browser at http:// azxxxxxx.vo.msecnd.net/images/test.jpeg
Tested content availability successfully on the browser at https:// storage.blob.core.windows.net/images/test.jpeg
inserted the Rewrite-redirect rule on the site web.config file
<rewrite>
<rules>
<rule name="CDN Redirection" stopProcessing="true">
<match url="^images/(.*)" />
<action type="Redirect" url="http:// azxxxxxx.vo.msecnd.net/images/{R:1}" />
</rule>
</rules>
</rewrite>
......( No using the custom subdomain name yet waiting for propagation)
Save, stop and restart website, clear cache, F12, inspect element .....nothing, content still being pulled straight up from the website
So what am I doing wrong?
Check my website at http://www.ehubcap.net
Thank you
This is a simple rule that is tested and works on Azure Websites:
<rule name="images redirection" stopProcessing="false">
<match url="images/(.*)" ignoreCase="true" />
<action type="Redirect" url="https://double.blob.core.windows.net/images/{R:1}" redirectType="Permanent" appendQueryString="true" logRewrittenUrl="true" />
</rule>
Note, you don't need the ^ in your match pattern.
You can check the result here - check the original page source first - IMG element refers to a local image: http://double.azurewebsites.net/images/some.jpg, which is being redirected by the URL Rewrite to the blob storage (you can redirect to any domain you wish).
Note, however, that URL Rewrite module is dependent on other modules. For best results, the UrlRewrite Module should be the first module to process the result. If you have enabled static and/or dynamic compression to compress the output, the URL rewrite will not work. This is because the default configuration kicks the compression module first, then brings the URL Rewrite module. And the URL Rewrite module cannot read compressed content. Yeah, don't ask me why. So, first disable compression (if you have enabled it) to check the URL rewrite config. Then try to reorder the modules. The simplest would be to first remove them, next add the URL Rewrite and then Compression module.
I have a ASP.NET MVC Web Site running with Siteminder SOO.
Al security is working correctly, except the Home Page.
In the SiteMinder configuration i have only one Realm with Resource Filter: "/" and Default Resource Protection: "Protected". So, all uris are protected. And i have rules for each uri, and a set of Domain Policies that works fine with these rules. The problem is the root page; i don't know how to write a Rule that allow access to the home page, for example: "http://misite.com/".
If I create a Rule with resource = "/", then the Effective Resource is: "my-siteminder-agent//". And a policy with this rule never applies.
¿How can i create a Rule to allow access to the home page for authenticated users?
I solved it using a Rule on SiteMinder to allow Access to '/Home' and a redirect with the IIS Rewrite Module.
<rewrite>
<rules>
<rule name="Root Hit Redirect" stopProcessing="true">
<match url="^$" />
<action type="Redirect" url="/Home" />
</rule>
</rules>
</rewrite>
You could also create a unprotected rule to allow the specific home page... ie index.htm
Change the rule to * instead of /*
If the entire site needs to be secured you do not need to create multiple rules for different paths. A standard rule covering everything will be sufficient. Refer to the Answer by #bcarroll to set that up. It will make your life easier when you have to make changes to the policies etc. later.
I have a WCF Web Service hosted inside a ASP.NET 4 environment (IIS 7.5 on Windows 7), and I would like to use URL Rewriting / Redirection.
The reason I need to do this is because I can't change some mobile device code to just insert the parameter.
Here is the URL I want:
http://server.test.com/VirtualDirectory/theOrganization/RequestService.svc/REST/GetIssueTypes
The real URL is:
http://server.test.com/VirtualDirectory/RequestService.svc/REST/GetIssueTypes?organization=theOrganization
Notice how I want to remove theOrganization and appended it to the Query string for redirection.
<rule name="test" stopProcessing="true">
<match url="(.+\.?)/(.+)/RequestService.svc/(.+)" />
<action type="Redirect" url="{R:1}/RequestService.svc/{R:3}?organization={R:2}"
redirectType="Permanent" />
</rule>
I know it's a little odd of a rule to write. Thinks i have my regular expression correct for matching. I run the expression in the URL Rewrite tester in IIS Manager, and it seems like it's matching what I want. Also, I do have IIS URL Rewrite installed, and I made a simple rule up and it worked.
However, when I try it using a browser, it failed to redirect and results in a 404. I was hoping a IIS Rewrite expert could chime in, as I am fairly new at it.
Thanks!
I tested your rule on a test server with iis 7.5 and url rewrite 2.0 and the rule is working, but your regex matches both your wanted url and the real url.
So you end up with a double redirect
I think you want your pattern something like this
(.+.?)/VirtualDirectory/(.+)/RequestService.svc/(.+)
Hope this helps.
I can't seem to get my head around these rewrite rules for some reason and I was hoping you guys could help. What I want is an outbound rule that will rewrite paths for link, img, script, and input tags.
I want to change this: http://www.mysite.com/appname/css/file.css
To this: http://cdn.mysite.com/css/file.css
So, basically I need to swap the host name and drop the app name from the URL. I've got the pre-condition filters to *.aspx files set already, but the rest seems like Greek to me.
EDIT for clarity
The appname in the URL above is an application in IIS. It's a placeholder for whatever appname happens to be in use. It could be any of over 50 different apps with our current setup. There will ALWAYS be an appname. Perhaps that will make the rule even easier.
The hostname, in this case www.mysite.com, can also vary slightly in terms of the subdomain. It might be www1.mysite.com, www2, etc. Also, just realized that I need to maintain the SSL if there.
So, I guess when it comes down to it, I really just need to take the URL, minus the appname, and append it to the new domain, while respecting the protocol that was used.
Original URL: http(s)://{host}/{appname}/{URL}
Output: http(s)://cdn.mysite.com/{URL}
I assume your website domain is always the same, then this rule should do:
<rule name="CdnRule" preCondition="OnlyAspx" >
<match filterByTags="Img, Input, Link, Script" pattern="^(.+)://.+?\.(.+?)/.+?/(.*)" />
<action type="Rewrite" value="{R:1}://cdn.{R:2}/{R:3}" />
</rule>
<preConditions>
<preCondition name="OnlyAspx">
<add input="{PATH_INFO}" pattern=".+\.aspx$" />
</preCondition>
</preConditions>
EDIT: changed according to clarified question
I assume the subdomain (www, www2, ...)is always there and it has to be ignored in target url.