Redirect with .php extension
b
Hi, I'm migrating a PHP website to Umbraco (10.6.1). The old url's need to be redirected to the new pages. For example, https://localhost:44363/contact.php needs to redirect to https://localhost:44363/nl/contact. But browsing to a url with '.php' or any '.*' does not invoke code in my project and immediately show a 404 page. My custom 404 page does not even show. Is this blocked by .net core or IIS perhaps? Thanks for any help.
s
You can add a
web.config
file with redirects in it. https://docs.umbraco.com/umbraco-cms/reference/security/ssl-https#redirect-traffic-on-iis This is a https redirect, but you can make your own. It might need some extra work, as it looks like
.php
is treated as a file, maybe give this a try: https://stackoverflow.com/a/46989139
r
Sounds like IIS site hasn't been set up to process the .php extension
s
No need, especially if you're not going to use php on that site.
don't bloat the pipeline with unused items 😁
h
It only needs that if you want to execute the php files, however you might need to map the .php extension to use the static file processor maybe
r
Yep, pretty sure you have to map the .php files to be processed by IIS, otherwise the request doesn't hit IIS at all which sounds like what the OP is experiencing. No need to install anything
s
When you drop a web.config in with redirects, it would never even need to hit any pipelines defined in IIS, which is why I recommended that route.
m
you do have to do a little more than drop a web.config in though this is required is it not?
Copy code
<system.webServer>
    <handlers>
      <remove name="aspNetCore"/>
      <add name="aspNetCore" path="*" verb="*" modules="AspNetCoreModule" resourceType="Unspecified"/>
    </handlers>
    <aspNetCore processPath="%LAUNCHER_PATH%" arguments="%LAUNCHER_ARGS%" stdoutLogEnabled="false" stdoutLogFile=".\logs\stdout" />
  </system.webServer>
or if you don't want add web.config you can add the same rules into an xml file and use AddIISUrlRewrite() ?? Also I find that kestrel is much better for local dev.. and these rewrites wouldn't get picked up then? (is it the case also that linux appservice on azure wouldn't observer these either?) plus an IRule in asp.net core opens up so much more functionality for rewrites if required and would work in all host configurations?
though.. https://learn.microsoft.com/en-us/aspnet/core/fundamentals/url-rewriting?view=aspnetcore-7.0#when-to-use-url-rewriting-middleware does take the view keep out of the pipeline if you can.. just like @Sebastiaan said. 😄
b
Ok thanks for the help folks. I'll have a look!
s
The question was for IIS so I answered for IIS 😉 But yes, if you have any other webserver you probably need some middleware!
2 Views