Link to home
Start Free TrialLog in
Avatar of rafaelrgl
rafaelrgl

asked on

url rewrite help

Hi, i have one page like this:
http://localhost/app_g/Default.aspx?id=173&S=1&M=12

I want to be rewrite like this:
http://localhost/photos/173/1/12

how can i accomplish this changing my web.config file to do this. What should I change on the web.config file.
Avatar of Edward Cho
Edward Cho
Flag of United States of America image

Avatar of rafaelrgl
rafaelrgl

ASKER

could you help me giving me one final solution to my problem, This link you show me is not working. can you provide me the syntax to add on web.config.
You should have a web.config like the one below:

<rewrite>
  <rules>
    <rule name="Rewrite to Default.aspx">
      <match url="^photos/([0-9]+)/([0-9]+)/([0-9]+)" />
      <action type="Rewrite" url="app_g/Default.aspx?id={R:1}&amp;S={R:2}&amp;M={R:3}" />
    </rule>
  </rules>
</rewrite>

Open in new window

i got this error:
Server Error

500 - Internal server error.
There is a problem with the resource you are looking for, and it cannot be displayed.
What does the event log say?

I'm assuming you have IIS7 with ASP.NET role service enabled?  URL Rewrite Mod installed?
Hi Edward, The page is like that:
http://localhost/app_g/Default.aspx?id=173&S=1&M=12
I want to be like this.
http://localhost/photos/173/1/12

Question, is your code doing the opposite
ASKER CERTIFIED SOLUTION
Avatar of Edward Cho
Edward Cho
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Hi, i found this on the internet that say i need to change the global.asax file like this, but it does not give errrors and does not change the path.

<%@ Import Namespace="System.Web.Routing" %>
<script runat="server">
    Sub RegisterRoutes(ByVal routes As RouteCollection)
        routes.MapPageRoute("test", "color/{id}/{*queryvalues}", "~/app_g/Details.aspx")
    End Sub
   
    Sub Application_Start(ByVal sender As Object, ByVal e As EventArgs)
        ' Code that runs on application startup
        RegisterRoutes(RouteTable.Routes)
    End Sub
ok, now i am starting to understand this. If i access the link:        
http://localhost:4565/app_g/Details.aspx?id=2 it will not change to the other page i route, but it will stay at this addres. But if I access this addres: http://localhost:4565/color/2/ it will work as the same. But what about if I access the first link with the ?id=2, is there anyway to change to the friendly path.

RouteTable.Routes.MapPageRoute("test", "color/{id}/{*queryvalues}", "~/app_g/Details.aspx")