We have a bilingual SharePoint website and would like to ensure that all French content is funnelled through our french domain, lets just call it _frenchdomain.com.
Languages variations in SharePoint are separated by folder structure, so in our case you can go to _http://englishdomain.com/en for English content and _http://englishdomain.com/fr for French content.
My question is how can I get IIS to recognize any instance of _http://englishdomain.com/fr/* and instead rewrite it as _http://frenchdomain.com/fr/*
<rule name="fr">
<match url="fr/.*"/>
<conditions>
<add input="{HTTP_HOST}" pattern="^frenchdomain.com$" negate="true" />
</conditions>
<action type="Redirect" url="http://frenchdomain.com/{R:0}" redirectType="Permanent"/>
</rule>
Related
A small introduction about the app's deployment & app in general:
We use .Net Core 6 MVC and is hosted in IIS. Additionally the application uses a domain which the actual website is hosted e.g. www.ExampleHost.com/ExampleApp.
Also we use Cloudflare to direct requests to a new domain for the website e.g. www.ExampleHost.com/ExampleApp -> www.Example-App.eu
Here is the problem, while the app works fine at www.ExampleHost.com/ExampleApp, if we enter www.Example-App.eu the directory of the app appears in the Url like www.Example-App.eu/ExampleApp in every request. That creates problem everywhere from returning Views to submitting Forms etc.
So an idea was to solve part of this problem by creating a web.config to configure URL Rewrite rules.
web.config
<rewrite>
<rules>
<rule name="RemoveExampleApp">
<match url=".*ExampleApp/(.*)" />
<conditions>
<add input="{REQUEST_METHOD}" matchType="Pattern" pattern="POST" ignoreCase="true" negate="true" />
</conditions>
<action type="Redirect" url="{R:1}"/>
</rule>
<rule name="RemoveExampleAppPost">
<match url=".*ExampleApp/(.*)" />
<conditions>
<add input="{REQUEST_METHOD}" matchType="Pattern" pattern="POST" ignoreCase="true" />
</conditions>
<action type="Rewrite" url="{R:1}" />
</rule>
</rules>
</rewrite>
But we still unable to perform POST requests.
Additionally, I read to another Stack Overflow post that it is possible to configure/fix that by of using routing instead of rewrite rules but we had no luck with that.
IIS URL Rewrite and .NET Core
We are open to any suggestions.
Thanks for your time.
Windows 2016 Server running IIS 10 with the URL Rewrite Module installed.
The servers are set up in a server Farm.
I've been messing around with this for the last 48 hours and cannot, for the life of me, figure out why it is not working as it is supposed to work.
I've looked at a video showing how to set it up and how it works, and I've mimicked what was done in the video, and nothing, still cannot get it to work.
This is what happens.
Using this code below will work; as you notice, it has the pattern="Pattern: "
However, the leading site that hosts the images has its images replaced with the stop-hotlinking.png image as well.
So, in theory, it works, but the hosting site has no access to its images to display.
If I remove (pattern="Pattern: "), it does not work.
To sum it up.
The below code will display the "stop-hotlinking.png" image on all outside sites, as well as the hosting site.
<rewrite>
<rules>
<rule name="STOP-Hot-Linking" enabled="true" stopProcessing="true">
<match url=".*\.(gif|jpg|png)$" />
<conditions>
<add input="{HTTP_REFERER}" pattern="Pattern: ^$" negate="true"/>
<add input="{HTTP_REFERER}" pattern="Pattern: ^https?://(www\.)?domain\.com/.*$" negate="true"/>
</conditions>
<action type="Rewrite" url="/graph/stop-hotlinking.png" />
</rule>
</rules>
</rewrite>
I even tried it with the pattern as this, and it will display the stop-hotlinking.png on all sites including the hosting site.
<add input="{HTTP_REFERER}" pattern="^http://(.*\.)?domain\.com/.*$" negate="true"/>
Below is the sample you could refer:
let's say I have 2 sites in my iis server and I would like to set a rule in the test site to not allow other domain sites to use images so I will set a URL rewrite rule in the test site.
test site index page contact:
<html>
<head>
<title>test.com title page</title>
</head>
<body>
<h2>test.com</h2>
<img src="http://test.com/img.jpg">
</html>
now i am trying to access image from the test site to the test2 site:
below is the rule i have set in my test site:
<rule name="Prevent Image Hotlinking" enabled="true" stopProcessing="true">
<match url=".*\.(jpg|jpeg|png|gif|bmp)$" />
<conditions>
<add input="{HTTP_REFERER}" pattern="^$" negate="true" />
<add input="{HTTP_REFERER}" pattern="^http://test.com/.*$" negate="true" />
</conditions>
<action type="Rewrite" url="/hotlink.jpg" logRewrittenUrl="true" />
</rule>
Note: hard refresh your page in bwroser if it does not work or you could try to open page in private mode.
I was assisted on another forum, and this was the issue.
I was testing the same image on multiple domains we own.
And that was the biggest problem, was the image would get cached, even when Google Tools was open, it would still cache it for whatever reason, we never could figure it out.
I changed to another image from the hosting site, and it started working.
We also found out that Google Chrome needed a referral meta tag in the head of the hosting sites page.
<meta name="referrer" content="origin">
Once all the above was taken care of and the following code in place. It started working.
<rule name="Prevent Image Hotlinking" enabled="true" stopProcessing="true">
<match url=".*\.(jpg|jpeg|png|gif|bmp)$" />
<conditions>
<add input="{HTTP_REFERER}" pattern="^https?://(www\.)?(?:DomainOne\.com|DomainTwo\.com|DomainThree\.com)/.*$" negate="true"/>
</conditions>
<action type="Rewrite" url="/graph/stop-hotlinking.png" logRewrittenUrl="true" />
</rule>
In the above, you will see there are multiple domains, this is to allow images to be hosted on their domains, and all other domains will get the STOP image.
This is completed.
I want to think Jalpa for trying to assist.
And gr8gonzo from the other forum for helping me out in this long venture.
This is definitely out of my area of expertise so I hope I explain this well. We have a website and within that website we have 2 different applications with 2 different login pages. What would I have to do so that for example requests for app1.website.com and app2.website.com get's routed to the correct apps login page?
WebServer Screenshot
you could try this rule:
<rule name="app1 redirect" stopProcessing="true">
<match url="(.*)" />
<conditions>
<add input="{HTTP_HOST}" pattern="app1.website.com" />
</conditions>
<action type="Rewrite" url="http://website.com/react1/app1/" logRewrittenUrl="true"/>
</rule>
I have a URL that looks like
https://thesite.com/m/?pageName=profileSettings#notifications
I need to rewrite it to
https://thesite.com/m/?pageName=notificationSettings
I'm trying something like
<rule name="m_notifications" stopProcessing="true">
<match url="^m/(.*)" />
<conditions>
<add input="{QUERY_STRING}" pattern="pageName=profileSettings#notifications" />
</conditions>
<action type="Rewrite" url="pageName=notificationSettings" appendQueryString="False"/>
</rule>
This isn't working, no errors, just not making any changes. What am I missing?
Thanks
It is not possible to do a rewrite based on the hash string. Browser doesn't transmit the part after hash to the server.
It's called Fragment identifier and is client side only. It's not possible in any language unless you are using some browser implementation (or software) which would send that part of URL to the server.
I want to ensure that anybody who goes to http://example.com/* gets automatically redirected to http://www.example.com/*. Currently, IIS allows either URL form to work, meaning that any page can be accessed at multiple URLs, which has a number of disadvantages (SEO, etc).
Is there any way to do this built into IIS (especially IIS 6) without setting up a third-party rewriting engine like this? It seems like a bazooka to kill a mosquito.
The easy way would be to simply remove the DNS entries for 'www.mysite.com', so the only DNS entries that exist are for 'mysite.com'.
Alternatively, here's a couple of techiques for redirecting to a canonical URI:
http://www.kalyani.com/2010/01/redirecting-to-canonical-url-in-iis7/
https://web.archive.org/web/20211020203216/https://www.4guysfromrolla.com/articles/072810-1.aspx
http://www.stevenhargrove.com/redirect-web-pages/
Basically you want to hand back a 301 Moved Permanently status for the non-canonical URIs, along with the canonical URI so the user agent may load it instead.
I have another solution for you:
<rule name="Canonical domain name" enabled="true" stopProcessing="true">
<match url="(.*)" />
<conditions>
<add input="{HTTP_HOST}" negate="true" pattern="^www\.([.a-zA-Z0-9]+)$" />
</conditions>
<action type="Redirect" url="http://www.{HTTP_HOST}/{R:0}" appendQueryString="true" redirectType="Permanent" />
</rule>