Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Remove HTML or ASPX Extension

In a hosted IIS7 environment, I am looking for the simplest way to use extension-less file names. Simply I have the following pages:

index.html (or .aspx) --> domain.com gallery.html --> domain.com/gallery videos.html --> domain.com/videos etc...

I only have a handful of pages, I have no dynamic code, nothing special. All the examples I have found or methods I use in other sites I've developed revolve around dynamic content, pages, etc. I am simply looking for the simplest solution, ideally not requiring any sort of url rewrite module installed. Preferably, I could keep the .html extension instead of converting the site to a ASP.NET project, but that is an option.

Thanks.

like image 900
roadsunknown Avatar asked Dec 19 '10 04:12

roadsunknown


People also ask

How do you remove a file extension in HTML?

The . html extension can be easily removed by editing the . htaccess file.

What does ASPX extension mean?

Active Server Pages (ASPX) is a file format used by web servers and generated using the Microsoft ASP.NET framework - an open-source development framework used by web developers to create dynamic web pages, often with the . NET and C# programming languages.

Is ASPX like HTML?

aspx is like an HTML page.

What does default ASPX mean?

Default. aspx - The default webpage loaded when a client browser requests a web server directory on a Microsoft IIS-based server that uses ASP.NET.


2 Answers

I ended up using the following sites:

http://blogs.msdn.com/b/carlosag/archive/2008/09/02/iis7urlrewriteseo.aspx

and

http://forums.iis.net/t/1162450.aspx

or basically the following code in my web.config file using the IIS7 URL Rewrite Module that most hosted sites now offer (in this case I am using GoDaddy):

<system.webServer>     <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> </system.webServer> 
like image 85
roadsunknown Avatar answered Oct 19 '22 23:10

roadsunknown


Another little bit more modern way to do this is using Microsoft.AspNet.FriendlyUrls. In the Global.asax.cs add:

void Application_Start(object sender, EventArgs e) {     // Code that runs on application startup     RouteConfig.RegisterRoutes(RouteTable.Routes); 

and in the RouteConfig file

public static class RouteConfig {     public static void RegisterRoutes(RouteCollection routes)     {         var settings = new FriendlyUrlSettings();         settings.AutoRedirectMode = RedirectMode.Permanent;         routes.EnableFriendlyUrls(settings);     } 
like image 20
Riga Avatar answered Oct 20 '22 01:10

Riga