Htaccess and change from html to php

My index.html had to change to php.
Bill’s DeSpam bric changes the page from html to php.
Therefore I must tell the htaccess file on the server that the index file has changed from html to php.
I searched the forum but could not find a solution.
Any idea?

I think I found a solution myself.

RewriteCond %{THE_REQUEST} ^./index.html
RewriteRule ^(.
)index.html$ https://yourdomain.de/$1 [R=301,L]

Seems to work.

Is this just for one page or all pages?

For a single page this should work:

Redirect 301 /index.html https://yourdomain.com/

That assumes you are using clean urls, otherwise change the last bit to .com/index.php

I tend to set pages to php nowadays by default. That way I know I won’t have to deal with this later on. It’s also required for certain CMS options.

1 Like

No clean urls.
But the code I use seems to work.

Thank you Flashman for your suggestion.
Will give it a try.

edit:
works perfect.
Thanks a lot.

Wonder why that is required. Is that different from host to host? I only get troubles if I have a index.html and index.php at the same time.

I never had to mess with the .htaccess to make that work.

Yeah, it would depend on how the default document has been set on your server. Usually, at least at the group I work for, 3 documents are set:

  • index.html
  • index.htm
  • index.php

The customer can (in our environment) define the priority or even alter those documents via the control panel.

But in some cases, only index.php is set, or something else, in which case you can use the .htaccess to set the default document.

This would also fix incoming traffic specifying index.html that now finds index.php, leading to a 404 not found. For me, this is yet another good reason to use clean urls, because it avoids this entirely.

1 Like

Try this…

RewriteEngine On
RewriteBase /

# Redirect .html to .php
RewriteRule ^(.+)\.html$ $1.php [L,R=301]