0

I'm having trouble making the pattern for matching the urls in a certain directory. I want to redirect users from mysite.com/posts/some-post.php to mysite.com/posts/some-post meaning that I want to remove the .php extension, but only in that directory, because I have already tried the universal rule which breaks my download urls which don't end with a .php extension

Here's the code that I'm currently using and which DOES NOT WORK

<rule name="Imported Rule 1" stopProcessing="true">
                <match url="^posts/([a-z0-9-])$" />
                <conditions logicalGrouping="MatchAll">
                    <add input="{REQUEST_FILENAME}" matchType="IsFile" ignoreCase="false" negate="true" />
                    <add input="{REQUEST_FILENAME}.php" matchType="IsFile" ignoreCase="false" />
                </conditions>
                <action type="Rewrite" url="{R:1}.php" />
            </rule>
  • Maybe I'm reading this wrong, but I think you need to take the .php out of the action line? This reads that you find a file with the .php, pull out REQUEST and then put .php right back onto it. – Mary Jul 24 '15 at 23:16
  • Sorry for that, I'm new with the whole URL rewrite thing and I haven't really found any resources about it. I've edited what you suggested, still no luck, but thank you, anyway. – user301299 Jul 24 '15 at 23:20
  • Ah, yeah, read too fast - that's what the server is doing, but apparently that is not what is seen. – Mary Jul 25 '15 at 00:03
  • Here we go, seems this is a solvable problem, but a tiny bit gnarly at it: https://www.saotn.org/iis-url-rewrite-hide-php-extension/ (posted the information from it but it disappeared, probably special character unhappiness, sorry, you'll have to go to the site to see what they did). – Mary Jul 25 '15 at 00:07
  • @Mary Oh, Mary, you're a life-saver! If I knew you I would buy a chocolate, thank you very much, this works great! – user301299 Jul 25 '15 at 00:11
  • @Mary - or you could put that in an answer and user301299 could accept it. In this way both of you will be helping others. (Comments aren't really made for answering) – Deer Hunter Jul 25 '15 at 07:17

0 Answers0