.NET MVC Routes to Handle Multiple PHP Pages

1/6/2016 9:38:04 PM

The following can be used to capture mutliple .php pages (or .html, html, etc pages) and redirect them to a controller. This controller could handle the final redirect to a new MVC Action and View.

You will also have to add a file handler so that Visual Studio and IIS will handle PHP page requests.

//redirect php to home page
routes.MapRoute(
	name: "Redirect - To Home"
	,url: "{old_page}"
	,defaults: new { controller = "Home", action = "Redirect_Main", id = UrlParameter.Optional }
	,constraints: new { old_page = @"(index.php|legacy.php|old.php|old.html|index.htm)" }
); 

//web.config
<configuration>
	....
	<system.webServer>     
		<handlers>
			<add name="PHPFileHandler" path="*.php" verb="GET" type="System.Web.Handlers.TransferRequestHandler" preCondition="integratedMode,runtimeVersionv4.0" />  
		</handlers>    
	</system.webServer>