what is the url rewriting?how to rewrite the url? give any
example
Answer Posted / 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 View All Answers
What is super () python?
How does php and apache work?
What is sorting php?
Can I include php in javascript?
For image work which library is used in php?
How to access standard error stream in PHP?
What is php pathinfo?
Explain me what is x+ mode in fopen() used for?
What are the steps involved to run php?
What are the 3 scope levels available in php and how would you define them?
How to set a page as a home page in a php based site?
What is use of header() function in php?
What is the current php version?
What is the difference between $_files['userfile']['name'] and $_files['userfile']['tmp_name']?
Do you know how to declare an array in php?