URL redirect

volety kiran 1 Reputation point
2021-10-29T16:47:46.573+00:00

Hi I have site with two different versions one the main site is in english and the other is for french version in fr folder

Now I woulld like to make only one main site in english and redirect all the french folder and its pages to root folder which has the same version

I mean I would like to move

https://mysite.com/fr/some-page-url.aspx to https://mysite/some-page-url.aspx

For this I have used the below web.config which works fine

<rule name="ES Redirect" stopProcessing="true">
<match url="^es/some-page-url.aspx" />
<action type="Redirect" url="https://www.mysite.com/some-page-url.aspx" redirectType="Permanent" />
</rule>

but the problem is If I navigate to https://www.mysite.com/es/
It is still showing the es default page

For this If I rewrite my web.config with below code

<rule name="ES Redirect0" stopProcessing="true">
<match url="^es/" />
<action type="Redirect" url="https://www.mysite.com" redirectType="Permanent" />
</rule>

Now the problem in this is all the pages are redirecting to the main site

Now finally I need to make both work at the same time ie..

I need to redirect

https://www.mysite.com/fr/some-page-url.aspx to the same version https://wwww.mysite.com/some-page-url.aspx
on the root path
as well as the default page

https://www.mysite.com/fr/ to https://www.mysite.com

Windows development Internet Information Services
Developer technologies ASP.NET Other
0 comments No comments
{count} votes

1 answer

Sort by: Most helpful
  1. Michael Taylor 60,161 Reputation points
    2021-10-29T17:47:10.08+00:00

    Redirect rules are a pain to figure out but not to hard once you understand the syntax. If I understand your goal then everything under 'https://www.mysite.com/fr/tohttps://www.mysite.com/`.

    Try this one, works for our scenarios but might not for yours.

    <rule name="Redirect to Root" stopProcessing="true">
                   <match url="^fr(/?.*)$" />
                   <action type="Redirect" url="https://{HTTP_HOST}{R:1}" appendQueryString="true" redirectType="Found" />
                </rule>
    

    Note that you should set the redirect types as temporary until you have it working correctly. Once you set it to permanent then browsers don't have to go back to the original URL ever again which makes testing very difficult.


Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.