what is the url rewriting?how to rewrite the url? give any
example



what is the url rewriting?how to rewrite the url? give any example..

Answer / chinnu

If you don't like having meaningless URL's for your
visitors (i.e index.aspx?id=3&pid=3932), consider URL Re-
writing. With URL rewriting, you can store all your content
in the database while having user-friendly URL's. Here's a
code snippet to do just this:

void Application_BeginRequest(Object sender, EventArgs e)
{
String strCurrentPath;
String strCustomPath;
strCurrentPath = Request.Path;
strCurrentPath = strCurrentPath.ToLower();
// the URL contains this folder name
if (strCurrentPath.IndexOf( "/SomeSubFolder/" ) > -1)
{
strCustomPath = "getContent.aspx?id=" +
Path.GetFileNameWithoutExtension( strCurrentPath );

// rewrite the URL
Context.RewritePath( strCustomPath );
}
}

The getContent.aspx will take the page name as a parameter
and do a lookup in the database and return the content for
the page. I have left the details out because the point of
the code snippet is to show how to rewrite the URL and get
the data from the database.

Is This Answer Correct ?    0 Yes 2 No

Post New Answer

More PHP Interview Questions

Who is the father or inventor of php?

0 Answers  


How many ways there are to fetch the data from the Database?

2 Answers   Tops Technologies,


Tell me how is it possible to know the number of rows returned in result set?

0 Answers  


How can we submit a form without using submit buttons?

0 Answers  


What is the goto statement useful for?

0 Answers  


How to get the DNS servers of a domain name?

1 Answers   Life Infotech,


What are computer variables?

0 Answers  


What are super global variables in php?

0 Answers  


Write a PHP code to print following number pattern: 123 456 789

5 Answers  


Why do we use interface in php?

0 Answers  


Php error constants and their descriptions

0 Answers  


What is the best way to avoid email sent through php getting into the spam folder?

0 Answers  


Categories