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

蓝咒 提交于 2019-12-25 05:09:06

问题


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> 


来源:https://stackoverflow.com/questions/10537910/htaccess-php-to-html-object-not-found-error

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!