Urlrewrite in asp.net
i am currently using IIS7's Url Re-write module, but the main loophole of using the IIS7's url re-write module, is that i have to write rule for all the page,which i want to use on the website, i want to use a comman rule and redirect it to particular page (say homepage) and using global.asax i can redirect it to desired page...
Is it possible with url re-write or is there any tool available i can use for this purpose, or a code sample that could help me doing this.
i dont want extension in the url.
i have pages like index.aspx, news.aspx, artists.aspx, lessons.aspx... i want the urls like index, news, lessons, artists, i created a rule in web.config like
< rewrite>
< rules>
< rule name="urlType1">
< match url="^(\w*)" />
< action type="Rewrite" url="default.aspx" appendQueryString="false" />
< /rule>
< /rules>
< /rewrite>
this will land any page to default.aspx, and then 开发者_如何学Pythonusing rawUrl in the global.asax, i am checking for the page like if user has entered "news" then i rewrite to news.aspx
Hope this has helped.
You can do just as you're suggesting in your question--redirect all requests to a single URL: And then in your Global.asax you could call Server.Transfer( "~/file1.aspx" ) to forward the request to a particular file.
Or, you could transfer directly from your URL Rewrite rule and skip further processing in your Global.asax file. For instance, this rule will read the incoming URL that has no file extention, and then forward the request on to a file that has a file extension:
<rule name="Append a file extension to all requests discard querystring" stopProcessing="true">
<match url="^(.*)\?" />
<action type="Rewrite" url="{R:1}.aspx" />
</rule>
Read more about URL Rewriting rules on Ruslan Yakushev's blog at http://ruslany.net/.
[EDIT] Okay, so for what you are asking...as far as I know, you do need to create a specific rewrite rule for each page. I was thinking more along the lines of MVC, where when you go to:
/news
it routes to
/default.aspx
which calls the NewsController.Index and displays the news page from default.aspx. However, to actually break everything out into individual pages and just trying to remove the extension...as far as I know, you have to create a new rule for each instance.
Redirect rules can be configured from the web.config files.
E.g. Here's what WordPress does in the web.config file that's included with WordPress:
<?xml version="1.0" encoding="UTF-8"?>
<configuration>
<system.webServer>
<rewrite>
<rules>
<rule name="wordpress" patternSyntax="Wildcard">
<match url="*"/>
<conditions>
<add input="{REQUEST_FILENAME}" matchType="IsFile" negate="true"/>
<add input="{REQUEST_FILENAME}" matchType="IsDirectory" negate="true"/>
</conditions>
<action type="Rewrite" url="index.php"/>
</rule></rules>
</rewrite>
</system.webServer>
</configuration>
The routes ALL traffic to the index.php page. The index.php file then reads what the URL is and spits out data based on the URL. It doesn't redirect it to a different page after the redirect, it--rather--decides what content to display.
MVC works along the lines of, you see this url:
/news > will call > NewsController.Index();
/news/index > will call > NewsController.Index();
/news/view > will call > NewsController.View();
/news/read/id > will call > NewsController.Read(id);
These Controllers, then typically get data from the database and apply the data to a "View" (html page that sits somewhere on the server with variables to display the data the controller passes to it).
精彩评论