0

How can I change the web rewrite url from (u/username) to (/username) like instagram.com/username

My web.config:

<rewrite>
<rules>
<rule name="Rule 1">
    <match url="^([a-zA-Z0-9_-]+)(|/)$" ignoreCase="false" />
    <action type="Rewrite" url="index.php?url={R:1}" appendQueryString="false" />
</rule>

<rule name="Rule 2" stopProcessing="true">
    <match url="u/([a-zA-Z0-9_-]+)(|/)$" ignoreCase="false" />
    <action type="Rewrite" url="/index.php?url=profile&amp;username={R:1}" appendQueryString="false" />
</rule>
</rewrite>

I tried some rules before but I can't figure it out.

2
  • According to your description, I couldn’t understand your requirement clearly, which url do you want to rewrite to which url? please give an example, I will make demo for you. Commented Jan 22, 2024 at 3:42
  • So, my first Rule is for all the pages e.x (/home, /register etc) and my second Rule is for the users profile page which the url is "mySite.com/u/username". I want to make this to "mySite.com/username" without the "u" in the url just a username next to url like the pages from Rule one. Is that possible? Commented Jan 22, 2024 at 7:24

1 Answer 1

0

If you want to rewrite mySite.com/u/username to mySite.com/username, you can refer to this rule:

<rewrite>
  <rules>
       <rule name="Remove u" stopProcessing="true">
            <match url="u/(.*)" />
            <action type="Rewrite" url=mySite.com/{R:1} appendQueryString="false" />
       </rule>
  </rules>
</rewrite>
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.