Greetings,
I am having trouble figuring out how to do a URL rewrite.
These are the rules I currently have:
<rewrite> <rules> <rule name="RedirectProjectURL" stopProcessing="true"> <match url="^project$" /> <conditions logicalGrouping="MatchAll"> <add input="{REQUEST_METHOD}" pattern="^POST$" negate="true" /> <add input="{QUERY_STRING}" pattern="^id=([^=&]+)$" /> <add input="{REQUEST_URI}" negate="true" pattern="^/project/([^/]+)/?$" /> </conditions> <action type="Redirect" url="project/{C:1}" appendQueryString="false" /> </rule> <rule name="RewriteProjectURL" stopProcessing="true"> <match url="^project/([^/]+)/?$" /> <conditions logicalGrouping="MatchAll"> <add input="{REQUEST_FILENAME}" matchType="IsFile" negate="true" /> <add input="{REQUEST_FILENAME}" matchType="IsDirectory" negate="true" /> </conditions> <action type="Rewrite" url="project?id={R:1}" /> </rule> </rules> </rewrite>
The idea is to redirect all requests from "project?id=N" to "project/N" and then rewrite all "project/N" requests to "project?id=N". However, what currently happens is the request gets redirected to "project/id/N" instead of getting rewritten. My guess is that after the rewrite it matches a DNN rule of some sort and it gets redirected. But I don't know where and how I can fix that.
Appreciate your help!
I've read that article before I decided to ask here. All of those are for redirecting rather than rewriting. I am not 100% sure but I do believe the rules I have are correct, as before I had them "project/N" was not going to "project/id/N". I am missing something.
Have you tried running the regex through any validators to be sure you have the correct regex? (I don't have the time to check it myself at the moment.)
https://regex101.com/
Yes, I ran it through the IIS regex testing tool. I also just ran it in regex101.com The regex seems to be working okay.
Yes, the idea is for the user to see only "project/N", but for the server to process that as "project?id=N" so I can get the id parameter. Could you please explain why I need outbound rules and what they need to do? Or maybe direct me to an article that I could read about this? Thank you.
Thanks for the response! However, this still doesn't fix my issue.
Scrap the outbound rule - this is not the part I need help with. The problem I need fixing is that when the user requests a page with the format "project/N" he gets redirected to "project/id/N". I don't know where that redirect comes from, but I want to stop it.
It happens only when the inbound rule for the rewrite is active. I tried your rule and mine (I had to remove the / at the start from your for it to work) and both have the same result.
Please let me know if you have any other suggestions.
I'm not sure I understand the issue correctly, but to me this seems as if DNN is rewriting the url for you. Did you add an exception for the rewriting to SEO > Expressions > Ignore URL Regular Expression?
These Forums are dedicated to the discussion of DNN Platform.
For the benefit of the community and to protect the integrity of the ecosystem, please observe the following posting guidelines:
Awesome! Simply post in the forums using the link below and we'll get you started.