changing sitecore website default URL structure - iis

I have a sitecore website with a default URL structure http:/ /www.domain.com/language/country/abc/xxx/........ due to SEO friendly we need to have language after country,Any idea if I can reset the format to something else,like http: //www. domain.com/country/language/abc/xxx/......?
can this be done on iis rewrite,if yes how.
thanks in advance

I suggest you specify your language and country so That I can match them in parameters.
Here is a sample for your reference:
<rule name="test" enabled="true" stopProcessing="true">
<match url=".*" />
<conditions>
<add input="{REQUEST_URI}" pattern="^([^/]+)/([^/]+)/(.+)$" />
</conditions>
<action type="Redirect" url="http://[www.domain.com]/{C:2}/{C:1}/{C:3}" />
</rule>

Related

Have Subdirectory of site in IIS show the index.html file when browsing to site

I am a fairly novice windows IIS guy, so any help I would greatly appreciate.
I have a client that requested all root Urls on their department websites redirect to their index.html page. So if a user, for example, goes to https://mysite.domain.com/, it will redirect to https://mysite.doman.com/index.html.
I did this through IIS 10 using a URLrewrite rule on the root of each site by doing the following.
<rule name="Index Request" enabled="true" stopProcessing="true">
<match url="^$" />
<action type="Redirect" url="https://mysite.domain.com/index.html" />
</rule>
This seemed to work.
The client now wants to have any of the subfolders of the root site show the index.html to any subdirectory sites of the root. Example. Https://mysite.domain.com/subdir/ “This is what shows now” to https://mysite.domain.com/subdir/index.html. Is there a way to do this in IIS?
Thanks in advance for any advice
I have made sure the index.html is the default document. I have also looked at User Friendly URL-template https://learn.microsoft.com/en-us/iis/extensions/url-rewrite-module/user-friendly-url-rule-template, but I am not sure if this is the right direction to go.
You can try this rule:
<rule name="test" enabled="true" stopProcessing="true">
<match url="^$" />
<action type="Redirect" url="/index.html" />
</rule>
<rule name="test1" enabled="true" stopProcessing="true">
<match url="^(.*)$" />
<conditions>
<add input="{REQUEST_URI}" pattern="^/([^/]+)" />
</conditions>
<action type="Redirect" url="/{C:1}/index.html" />
</rule>
<rule name="SEF Rule" stopProcessing="true">
<match url="^(.*)$" ignoreCase="false" />
<conditions logicalGrouping="MatchAll">
<add input="{REQUEST_FILENAME}/index.html" matchType="IsFile"
ignoreCase="false" />
</conditions>
<action type="Redirect" url="{R:1}/index.html" />
</rule>

URL Rewriting the path in IIS

I have a site that uses two characters in the URL path to determine the initial language e.g. https://my.company.net/Monitoring/gb displays in the English language. I want to setup a redirect for these two display the full culture code e.g. https://my.company.net/Monitoring/en-GB
This is the rule that I've tried:
<rewrite>
<rules>
<rule name="Monitoring gb rewrite" patternSyntax="ExactMatch" stopProcessing="true">
<match url="https://my.company.net/Monitoring/gb" />
<conditions />
<serverVariables />
<action type="Redirect" url="https://my.company.net/Monitoring/en-GB" appendQueryString="false" />
</rule>
</rules>
</rewrite>
I expected https://my.company.net/Monitoring/gb to redirect to https://my.company.net/Monitoring/en-GB however this rule does not have any effect: the browser URL stays at https://my.company.net/Monitoring/gb.
How can I rectify this?
You could use below url rewrite rule.
<rule name="gb to en-gb redirect" stopProcessing="true">
<match url="(.*)" />
<conditions>
<add input="{HTTP_HOST}" pattern="ww.sample1.com" />
<add input="{HTTPS}" pattern="on" />
<add input="{REQUEST_URI}" pattern="Monitoring/gb" />
</conditions>
<action type="Redirect" url="https://www.sample1.com/Monitoring/en-GB" />
</rule>
Note: use your hostname instead of the www.sample1.com.
The redirect failure was due to browser caching. The redirect works once the cache is cleared.

IIS rewrite rule not triggered when file-name plus extension is in the url

I am struggling getting an IIS rewrite rule working.
The old urls look like:
https://wwww.testserver.com/package.aspx?TrackingNumber=number
The new web app is expecting the urls in this format:
https://wwww.testserver.com/package/number
Currently I have the following rule setup, which is not working.
<rule name="Rewrite to new Package site" stopProcessing="true">
<match url="^package\.aspx\?TrackingNumber=([_0-9a-z-]+)" />
<action type="Redirect" url="https://www.testserver.com/package/{R:1}" logRewrittenUrl="true" />
</rule>
The interesting part is, if I remove package.aspx\? from the rule, urls like these https://wwww.testserver.com/oldwebsite/TrackingNumber=number are getting matched.
In my test calls I replaced package.aspx with package.html and these urls are not getting matched as well. It looks like IIS ignores urls with filenames in the url.
You could use below url rewrite rule to redirect https://wwww.testserver.com/package.aspx?TrackingNumber=number to https://wwww.testserver.com/package/number:
<rule name="test" stopProcessing="true">
<match url="(.*)" />
<conditions>
<add input="{REQUEST_FILENAME}" pattern="package(.aspx)" />
<add input="{QUERY_STRING}" pattern="TrackingNumber=(.*)" />
</conditions>
<action type="Redirect" url="http://localhost:2568/package/{C:1}" appendQueryString="false" />
</rule>
Note: You could modify hostname as per your requirement.
Regards,
Jalpa

IIS web.config redirect subfolder to domain

I have a strange problem with IIS url_rewrite module and web.config setup. I think there is a problem with the matching pattern or I'm doing something completely wrong..
My setup is a ASP.Net MVC app with multi language support. For starters I have three languages enabled, English, German and French.. so you could access them with a language parameter www.domain.com/en/ www.domain.com/de/ www.domain.com/fr/.. now I bought a german domain and setup up the german part of the page to .de domain, so now I have www.domain.com/en/ www.domain.de/de/ www.domain.com/fr/ everything ok so far..
The problem i'm trying to figure out how to add a safe 301 redirect if you write www.domain.com/de/ to www.domain.de/de/ or vice versa www.domain.de/en/ back to www.domain.com/en/ ... the main reason i wan't to solve this its because of SEO to fix the duplicate content issues ..
I have IIS 8.5, url_rewrite module installed and now I'm stuck with this in the in my web.config
<rule name="DE Redirect" stopProcessing="true">
<match url="(.*)" ignoreCase="true" />
<conditions logicalGrouping="MatchAny">
<add input="{HTTP_HOST}" pattern="^www\.domain\.com\/de\/$" />
</conditions>
<action type="Redirect" url="https://www.domain.de/de/{R:0}" redirectType="Permanent" />
</rule>
I want to redirect the user if they enter or get to www.domain.com/de/page1 to www.domain.de/de/page1 and only if there is the www.domain.com/de/ in the url, I won't redirect if they enter to english of french language website.
Any idea what am I doing wrong or what is the best way to debug such redirects.. I have tried with the Failed Request Tracing but didn't found anything helpful.
Any ideas?
Cheers
Because answers cannot contain domain.com, then I will use everywhere example.com and example.de
You should use redirect like that:
<rule name="DE Redirect" stopProcessing="true">
<match url="^de/(.*)" ignoreCase="true" />
<conditions>
<add input="{HTTP_HOST}" pattern="^www\.example\.com$" />
</conditions>
<action type="Redirect" url="https://www.example.de/de/{R:1}" redirectType="Permanent" />
</rule>
Also if you want to prevent opening the French language on German domain https://www.example.de/fr and redirect it to https://www.example.com/fr then you should also add
<rule name="FR Redirect on DE domain" stopProcessing="true">
<match url="^fr/(.*)" ignoreCase="true" />
<conditions>
<add input="{HTTP_HOST}" pattern="^www\.example\.de$" />
</conditions>
<action type="Redirect" url="https://www.example.com/fr/{R:1}" redirectType="Permanent" />
</rule>

IIS: Redirect subdomain to specific url

In IIS 8, I want to redirect the url http://test.example.com to http://www.example.com/abc/123
I try this, but not work.
<rule name="test" stopProcessing="true">
<match url="^test.example.com$" />
<action type="Redirect" url="http://www.example.com/abc/123" />
</rule>
you could add the pattern like this
<rule name="RedirectDomain" enabled="true" stopProcessing="true">
<match url=".*" />
<conditions logicalGrouping="MatchAny" trackAllCaptures="true">
<add input="{HTTP_HOST}" pattern="(.*)test.example.com />
</conditions>
<action type="Redirect" url="http://www.example.com/abc/123" redirectType="Permanent" />
</rule>
In the IIS GUI on the given side you should be able to choose 'HTTP Redirect' from there you can type in a url to redirect the site to.
I don't know if this approach is the recommended (It is normally used to redirect HTTP request on a given site to use HTTPS), but it will solve your problem.

Resources