When used at site level, the IIS7 URL Rewrite 2 module saves its configuration in the web.config file of that site. I'm using Sitecore CMS, and best practice is to store any web.config customisations in a separate config file for ease of upgrading, staging/production setups etc.
Is there any way to specify a different config file for IIS7 redirects?
I know that application-level rewrites are stored in ApplicationHost.config, but I have several sites running on the server and would like to keep them separated.
Thanks, Adam
In order to support this best practice you've mentioned, Sitecore implements pluggable configs, but only for the elements inside <sitecore> section of web.config. So, unless IIS7 URL rewrite provides some way to move its stuff to a separate config (like ASP.NET does for connectionstrings.config), I'm afraid you'll have to keep it in the main web.config file.
Sorry if I'm saying obvious things.
You can also try to use rewrite maps
<rewrite>
<rewriteMaps configSource="rewriteMaps.config" />
</rewrite>
Sample rewriteMaps.config file:
<rewriteMaps>
<rewriteMap name="CustomRewrites" defaultValue="">
<add key="/instructions" value="/documents" />
</rewriteMap>
</rewriteMaps>
I'm not familiar with the url rewriting config, but I have an example of moving the url mapping to a separate file:
<urlMappings configSource="config\urlMappings.config"></urlMappings>
And that file looks like the following:
<?xml version="1.0"?>
<urlMappings enabled="true">
<add url="~/somedealer" mappedUrl="/?theme=4" />
<add url="~/someotherclient" mappedUrl="/?theme=12" />
</urlMappings>
I'm sure the url rewriting works the same way.
Related
I have the following situation:
Multiple web sites running on IIS 10.0
Web sites running on the same account of a shared hosting service, so no access to machine.config or other configuration files outside the hosting environment
Each of the web sites share a common set of rewrite rules, but also define their own site specific rewrite rules
Now I want to move the common rewrite rule set to an external file, so it is easier to maintain. Then I want to include these common rule set into the web.config of each site.
I have looked into the following several options, but found out that none of them worked:
Add a configSource attribute to the <rewrite> tag. This does not work, as the <rewrite> does not allow the configSection attribute
Add a configSource attribute to the <rules> tag. This does not allow me to extend the rules for a specific site, as it only reads the configuration from the file that is mentioned in the configSource attribute
Add a file attribute to the <rules> tag. This did not process the rules in the external file. Maybe the format of my external is incorrect then (see below for how this last option is configured).
When using the file attribute my web.config was looking like this (only the relevant parts are shown):
<?xml version="1.0" encoding="UTF-8"?>
<configuration>
<system.webServer>
...
<rewrite>
<rules file="rules.config" />
<!-- here I want to add some additional rules, but they were not there during my initial tests -->
</rewrite>
...
</system.webServer>
</configuration>
My rules.config was like this (only relevant parts shown):
<?xml version="1.0" encoding="UTF-8"?>
<rules>
<clear />
<rule ...>
...
</rule>
</rules>
Is there a way to accomplish what I want? As mentioned above, I do not have access to the IIS configuration files outside of my hosting environment, so I cannot place common rules in the machine.config or the ApplicationHost.config files.
I want to create a default document called default and in that document I want it to rewrite the URL so instead of going www.bob.com it should instead go to www.bob.com/uv
Right now this is being done through URL rewrite rules, with patterns and all kinds of complications. I saw this done directly in the default document once, I cant remember if it was default.htm or .html or .aspx, using one line of code and I was very intrigued but I have not found it since then and no good examples have come up in my google searching. Does anyone have a link or could write the single line of code to add \uv to the url? Is there a really good example of it anywhere?
You can add which ever default page you want from IIS Manager -> -> Default Document - > Add (on right side) or by adding below in your web.config
<?xml version="1.0" encoding="UTF-8"?>
<configuration>
<system.webServer>
<defaultDocument>
<files>
<add value="default.aspx" />
</files>
</defaultDocument>
</system.webServer>
</configuration>
However this is a rewrite i.e. this will load default.aspx when you browse www.bob.com (URL remains same but the page is actually loaded).
If you want to actually change the URL (redirect) then with the same configuration above this below line in default.aspx
<%Response.Redirect("home.aspx")%>
We’re running into an issue where the URL rewrites we are using in the child application are not working. I suspect this is due to Composite overriding the rewrites.
Is there a guide to creating child applications under Composite, or a way to tell it to not use the default Composite Rewrite engine for child applications?
The solution we went with was to move the application from being under Composite, to the Root level of the website and took care of any linking issues with rewrites. This will work until a better solution is found.
It isn't Composite-specific, but if the rewrites are in the web.config
It isn't Composite-specific, but if the rewrites are in the web.config (editable through the Composite interface) you should be able to wrap their parent node in a <location> tag:
<location path="." inheritInChildApplications="false">
<system.webServer>
<rewrite>
...
</rewrite>
</system.webServer>
</location>
I have React app which ends up being built with webpack. We host an API which this app talks to on Azure and would like to host the UI built on top of it out there as well.
When hitting the URL the first time, and navigating around, all of the history location stuff works. However, when we refresh the page, we receive a 404 error (which is to be expected if IIS is serving this).
Is it possible to configure Azure to handle this sort of thing? Should we just give up on this type of application and host a webpack vm?
Similar questions:
Reactjs HistoryLocation get 404 on refresh
React-router urls don't work when refreshing or writting manually
If do understand your question and situation correctly, the solution would be to redirect all requests to your only one HTML page (assuming index.html).
This can be achieved with the URL rewrite module of IIS.
By default any Azure Web App will have a file in its web root folder named web.config. This is standard XML file. Open it with favorite editor and locate <system.webserver> section. Then place the following additional sections inside. Note, the <rewrite> element should be direct descendant of the <system.webserver> one:
<rewrite>
<rules>
<rule name="Rewrite to index.html">
<match url=".*" />
<action type="Rewrite" url="index.html" />
</rule>
</rules>
</rewrite>
Again, based on the assumption that you serve everything from index.html, you can change this file in the rewrite rule to represent the file you are serving content from.
I'm trying to set up 301s for a site which will bounce all old pages to the homepage (it was a large site that is now a single page).
The server's Windows based, however, so no htaccess fun for me.
Could anybody assist with producing a web.config file that redirects everything to the homepage via 301s?
This may work:
<?xml version="1.0" encoding="UTF-8"?>
<configuration>
<system.webServer>
<rewrite>
<rules>
<rule name="301 Redirect Everything To Home" stopProcessing="true">
<match url=".+" />
<action type="Redirect" url="/" redirectType="Permanent" />
</rule>
</rules>
</rewrite>
</system.webServer>
</configuration>
But is will redirect everything, including images, include files etc.
Could you explain your motive for this as generally it's a bad move. It causes a poor user experience, robots don't like it, and nothing knows if a page is really missing or not.
I suggest you to try "IsapiRewrite" 3rd party module/DLL
ISAPI_Rewrite is a powerful regular-expressions-based URL rewriter for
IIS. It is compatible with Apache mod_rewrite making it possible to
move configurations from Apache to IIS and vice versa just by copying
.htaccess files (please see this compatibility chart). It is used for
search engine optimization, to proxy another server's content, stop
hotlinking or strengthen server security.