How come stackoverflow hasn't any .aspx page suffix in the url bar? Everything ends up in /something/ or /page
How can I achieve the same in asp.net?
Instead of webforms (and aspx pages) you could use MVC and it's routing feature (see http://www.asp.net/mvc/overview/controllers-and-routing) where a url is mapped to an "action" in a "controller".
A URL of /questions/25364620/whatever could be mapped to the "Index" action (a default value) of the "QuestionsController" ("questions" from the URL + "Controller"), with an id parameter of 25364620. The title is ignored.
These are called the friendly urls. I am not sure about how they have written in Stackoverflow but you can remove the .aspx entension by doing like this:
<rewrite>
<rules>
<rule name="RewriteMyASPX">
<match url="(.*)" />
<conditions logicalGrouping="MatchAll">
<add input="{REQUEST_FILENAME}" matchType="IsFile" negate="true" />
<add input="{REQUEST_FILENAME}" matchType="IsDirectory" negate="true" />
</conditions>
<action type="Rewrite" url="{R:1}.aspx" />
</rule>
</rules>
</rewrite>
Related
we migrate our webapp hosted in a directory "webapp" inside main domain:
http://www.example.com/webapp/
To the new subdomain without "webapp" folder:
http://subdomain.example.com/
I need to redirect only subdir "webapp". I don't want to redirect other url like http://www.example.com/, http://www.example.com/folder1, http://www.example.com/folder2, ....
But we have already sent a lot of emails to customers with link inside like: LOGIN TO YOUR DASHBOARD or other link like DOWNLOAD YOUR DOC
Now i'm trying to do a redirect trough web.config but it seem that nothing work.
If I try no navigate to, for example, http://www.example.com/webapp/login i don't get redirected to http://subdomain.example.com/login/ as expected.
If I try no navigate to, for example, http://www.example.com/webapp/data/download.php/id=43 i don't get redirected to http://subdomain.example.com/data/download.php/id=43 as expected.
Any suggest?
<rule name="redirect-to-subdomain" stopProcessing="true">
<match url="^webapp/$" />
<conditions>
<add input="{REQUEST_FILENAME}" matchType="IsFile" negate="true" />
<add input="{REQUEST_FILENAME}" matchType="IsDirectory" negate="true" />
</conditions>
<action type="Redirect" url="http://subdomain.example.com/{R:0}" redirectType="Permanent" />
</rule>
You rule won't work except for http://www.example.com/webapp/.
If you want to redirect link like http://www.example.com/webapp/login. Please try this rule.
<rule name="redirect-to-subdomain" stopProcessing="true">
<match url="^webapp/(.*)$" />
<conditions>
<add input="{REQUEST_FILENAME}" matchType="IsFile" negate="true" />
<add input="{REQUEST_FILENAME}" matchType="IsDirectory" negate="true" />
</conditions>
<action type="Redirect" url="http://subdomain.example.com/{R:1}" redirectType="Temporary" />
</rule>
I created a aspx blog website which creates page dynamically.
and uses unique id generated at the time of page creation as it's name.
eg:
http://www.websitename.com/2016/f1.aspx
http://www.websitename.com/2016/f2.aspx
http://www.websitename.com/2016/f3.aspx
If i use this naming convention, do i have to worry about SEO problems?
whether the the search engines index my website and the blogs?
I need to change the dynamically created page name to the page title. How can i do it?
and also i need to remove the .aspx from the blog page.
eg :
/f1.aspx => /HelloWorld
/f2.aspx => /ThisCode
Try this... although i didn't tried it myself yet... but i am pretty sure ..it should work... Add these lines in your webconfig to remove .aspx extension from the end...
<configuration>
<system.webserver>
<rewrite>
<rules>
<rule name="RemoveASPX" enabled="true" stopProcessing="true">
<match url="(.*)\.aspx" />
<action type="Redirect" url="{R:1}" />
</rule>
<rule name="AddASPX" enabled="true">
<match url=".*" negate="false" />
<conditions>
<add input="{REQUEST_FILENAME}" matchType="IsFile" negate="true" />
<add input="{REQUEST_FILENAME}" matchType="IsDirectory" negate="true" />
<add input="{URL}" pattern="(.*)\.(.*)" negate="true" />
</conditions>
<action type="Rewrite" url="{R:0}.aspx" />
</rule>
</rules>
</rewrite>
</system.webserver>
Try these links.... these might come handy
how to change title of aspx page dynamically on page load
Page.Title vs Title tag in asp.net
how can i create a dynamic page in asp.net (C#)?
I have a requirement to hide any type of page extension in my site which have hosted 100 more page asp,html and aspx pages.
I want to hide all type page extension . I use following code which only works for .aspx. not work on .html & .asp page extension
<rule name="RemoveASPX" enabled="true" stopProcessing="true">
<match url="(.*)\.aspx" />
<action type="Redirect" url="{R:1}" />
</rule>
<rule name="AddASPX" enabled="true">
<match url=".*" negate="false" />
<conditions>
<add input="{REQUEST_FILENAME}" matchType="IsFile" negate="true" />
<add input="{REQUEST_FILENAME}" matchType="IsDirectory" negate="true" />
<add input="{URL}" pattern="(.*)\.(.*)" negate="true" />
</conditions>
<action type="Rewrite" url="{R:0}.aspx" />
</rule>
<match url="(.*)\.(aspx|php|html)" />
<action type="Rewrite" url="{R:0}.{R:1}" />
You can change regex of the match element so it matches on the other extensions.
You can (and should) use the routing mechanism provided by Asp.NET, in your specific case the MapPageRoute method as described here: http://msdn.microsoft.com/en-us/library/vstudio/dd329551%28v=vs.100%29.aspx
What you see about aspx pages can be applied to other kind of pages too, like plain html or old asp.
I had developed a Web application in Asp.net. When am using the Application over IIS, the file extension as.aspx is visible. Is it possible to hide it (or) rename it....Thankx in advance.
For .NET framework 4.0+, try the following rule in web.config (inside <system.webServer>):
The first will redirect URLs using the old format, to remove the .aspx extensions. You should of course update your links as well - eventually you won't need this.
The second rule rewrites URLs internally to add .aspx behind the scenes.
<rewrite>
<rules>
<rule name="RedirectOldFormat" enabled="true" stopProcessing="true">
<match url="(.*)\.aspx" />
<action type="Redirect" url="{R:1}" />
</rule>
<rule name="InternallyAddAspx" enabled="true">
<match url=".*" negate="false" />
<conditions>
<add input="{REQUEST_FILENAME}" matchType="IsFile" negate="true" />
<add input="{REQUEST_FILENAME}" matchType="IsDirectory" negate="true" />
<add input="{URL}" pattern="(.*)\.(.*)" negate="true" />
</conditions>
<action type="Rewrite" url="{R:0}.aspx" />
</rule>
</rules>
</rewrite>
For .NET Framework 3.5 or earlier, you can accomplish this using routing. Try the following solution:
http://www.codedigest.com/Articles/ASPNET/294_Search_Engine_Friendly_URLs_Using_Routing_in_ASPNet_35.aspx
I am using following web.config entry for url rewriting to remove .aspx extension.
<rewrite url="~/(.+)" to="~/$1.aspx" />
The problem I am getting here is if I have any image on page, it assigns .aspx extension to image.
Also if I tried to access my site like http://exmaple.com, it get redirected to http://exmaple.com/default.aspx.aspx.
I want to know if there is any way to add ignore case in web.config.
Your rewrite should look something like this, to remove .aspx
<rewrite>
<rules>
<rule name="RewriteASPX">
<match url="(.*)" />
<conditions logicalGrouping="MatchAll">
<add input="{REQUEST_FILENAME}" matchType="IsFile" negate="true" />
<add input="{REQUEST_FILENAME}" matchType="IsDirectory" negate="true" />
</conditions>
<action type="Rewrite" url="{R:1}.aspx" />
</rule>
</rules>
</rewrite>