IIS URL REWRITE PHP pages

ANIS 136 Reputation points
2021-07-18T17:48:42.463+00:00

Hello,

When i write the following URL, the webserver return a error :

http://mydomain/mypage

but if i correct the URL like this : http://mydomain/mypage.php

the URL works well.

Do you know why ? Have you any solution to make the URL working well without le .php at the end ?

perhaps a regular expression to put on the URL REWRITE IIS module ?

Thank you for your help.

Internet Information Services
0 comments No comments
{count} votes

Accepted answer
  1. HuryShen - MSFT 321 Reputation points
    2021-07-19T03:02:50.08+00:00

    Hi @ANIS ,

    As CarstenRiedel mentioned, if you enforce this rule before the https rewrite, it may lead to this problem.

    If not, you can also refer to the url rewrite rule I provided below to add ".php" in your request:

       <rule name="redirectRule1" stopProcessing="true">  
       <match url="(.*[^/])$" />  
       <conditions>  
         <add input="{REQUEST_FILENAME}" matchType="IsFile" negate="true" />  
         <add input="{REQUEST_FILENAME}" matchType="IsDirectory" negate="true" />  
         <add input="{REQUEST_FILENAME}" pattern="(.*?)\.[a-zA-Z]{1,4}$" negate="true" />  
       </conditions>  
       <action type="Rewrite" url="{R:1}.php" />  
       </rule>  
    

    If the answer is helpful, please click "Accept Answer" and upvote it.

    Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.


1 additional answer

Sort by: Most helpful
  1. Carsten Riedel 11 Reputation points
    2021-07-18T20:25:15.073+00:00

    I think the confusion is about, is the "mypage part" a directory or a file.

    Maybe you enforce this rule before the https rewrite (saw your other post)

    https://stackoverflow.com/questions/14816776/iis-forces-slash-even-with-url-rewrite-to-remove-it
    https://ruslany.net/2009/04/10-url-rewriting-tips-and-tricks/#trailing-slash

    0 comments No comments

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.