can anybody please tell me
how rewrite .php files to .html files in a folder.
or how to rewrite urls like http://examle.com/files/ (actual path http://example.com/files.php)
using web.config file.

You can try this:

<?xml version="1.0" encoding="UTF-8"?>
<configuration>
    <system.webServer>
        <rewrite>
            <rules>
                <rule name="Serve PHP files sans ext" stopProcessing="true">
                    <match url="^(.*)$" />
                    <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>
            </rules>
        </rewrite>
    </system.webServer>
</configuration>
Member Avatar

diafol

for this use apache rewrite. there are many tutorials online

^ what he said

@cilla yeah it is working . thank you so much sir.... u given complete code . thank you so much again ...

@diafol ya there are many in online. but i like this website most. programming experts were here . this is a small google search. thank you http://www.daniweb.com

@cilla
sir i was tried your example
http://example.com/files.php which rewrites http://example.com/files
ok fine

i added the following line for directory (like this http://example.com/files/ ) but am not getting can you help me
<add input="{REQUEST_FILENAME}" matchType="IsDirectory" negate="true" />

 <configuration>
<system.webServer>
<rewrite>
<rules>
<rule name="Serve PHP files sans ext" stopProcessing="true">
<match url="^(.*)$" />
<conditions logicalGrouping="MatchAll">
<add input="{REQUEST_FILENAME}" matchType="IsFile" ignoreCase="false" negate="true" />
<add input="{REQUEST_FILENAME}.php" matchType="IsFile" ignoreCase="false" />

<add input="{REQUEST_FILENAME}" matchType="IsDirectory" negate="true" />
</conditions>
<action type="Rewrite" url="{R:1}.php" />
</rule>
</rules>
</rewrite>
</system.webServer>
</configuration>

htaccess is the best way to ago. Try: AddType application/x-httpd-php .html in your htaccess file.

sir , htaccess is not supporting my server thats why using web.config (windows hosting)

Member Avatar

diafol

@raj. i apologize if my post was a little curt but i'm on bacation and im using a mobile so i was just trying to point you in the right direction. complete code solutions aren't really what this site is about though. we did not know that you were on iis so its a good thing that i didnt waste 10 minutes of my time typing out a htacces solution.