Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Remove .html extension from URLs in Windows Server

I have a website hosted on GoDaddy and I just realized they use Windows Servers not Apache. Which means using an .htaccess file doesn't work.

I want to remove the .html and .php extension from all website URLs.

Basically, the question is: How do you re-write this (which would go in the .htaccess file) for a Windows Server?

RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME}\.html -f
RewriteRule ^(.*)$ $1.html
like image 212
alejorivera Avatar asked Dec 17 '25 01:12

alejorivera


1 Answers

Solved it!

You can accomplish this by creating a web.config file with the following code:

<configuration>   
 <system.webServer>   
    <rewrite>          
        <rules>             
            <rule name="RewriteHTML">
              <match url="(.*)" />
                <conditions logicalGrouping="MatchAll">                     
                <add input="{REQUEST_FILENAME}" matchType="IsFile" negate="true" />                     
                <add input="{REQUEST_FILENAME}" matchType="IsDirectory" negate="true" />                 
                </conditions>                 <action type="Rewrite" url="{R:1}.html" />             
            </rule>                
        </rules>      
    </rewrite>   
 </system.webServer>  
</configuration>
like image 71
alejorivera Avatar answered Dec 22 '25 11:12

alejorivera



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!