htaccess *.php to *.html object not found error

2019-09-15 21:43发布

问题:

I am trying to transform URLs from index.php to index.html, servicii.php to servicii.html and so on.

I wrote in my .htaccess file, which is in my site root the following code:

<IfModule mod_rewrite.c>  
    RewriteEngine On  
    RewriteBase     /
    RewriteRule     ^(.*)\.php$   $1.html [R=permanent] 
</IfModule> 
?>

But when I follow "Prima pagina" (Home) or "Servicii" (the only 2 pages created on site) it gives me a 404 error

Also, I have the code

<IfModule mod_rewrite.c>
    RewriteEngine on
    RewriteBase  /fetesti/
    RewriteRule  ^(.*)\.php$   $1.html [R=permanent] 
</IfModule>

on my local machine, which is XAMPP based. It gives me Object not found 404, and on my Apache log:

file not found [...]/index.html;

I know the rewrite engine is working (I wrote gibberish and it gave me 505 internal server error and made other tests)

What am I doing wrong?

回答1:

Try just remove [R] permanent redirect, and switch extensions in rule

<IfModule mod_rewrite.c>  
    RewriteEngine On  
    RewriteBase     /
    RewriteRule     ^(.*)\.html$   $1.php
</IfModule>