我正在重新设计HTML格式的PHP网站由于文件扩展名,我是否需要设置重定向?

问题描述

我正在重新设计一个当前为PHP网站的网站。新站点将全部为HTML。我正在尝试使所有子弹保持相同。我应该设置重定向吗?

当前,网站页面在浏览器中具有.PHP扩展名。

示例:https://www.dehartsystems.com/residential.php

页面将是HTML,URL将没有文件扩展名。

示例:https://www.dehartsystems.com/residential

由于文件扩展名将更改,我是否需要设置重定向

解决方法

要回答您的问题,是的,您确实需要设置重定向。通常,这是在服务器上html文件夹根目录中的.htaccess文件中完成的。

在此.htaccess文件中,您放置了:

# Check rewriting is possible.
<IfModule mod_rewrite.c>
    # Turn on Rewrite engine
    RewriteEngine on
    # check if file does not exist.
    RewriteCond %{REQUEST_FILENAME} !-f
    # check if folder does not exist.
    RewriteCond %{REQUEST_FILENAME} !-d
    # rewrite the given URL.
    RewriteRule ^(.*).php$ $1.html [R=301,L]
</IfModule>

这会将所有调用重定向到在相同文件夹位置,具有相同文件名的HTML文件中不存在的任何.php文件。

参考:

https://htaccessbook.com/add-remove-change-file-extensions-htaccess/

另请参阅How to change the PHP file extension using .htaccess file on GoDaddy Linux Hosting?

,

是的,如果您不这样做,则需要将每个文件重命名为.HTML,这样浏览器就不会将该文件识别为代码。 “ https://www.dehartsystems.com/residential.html”只有这样您的网站才能正常工作。也就是说,您应该将Residential.php重命名为Residential.html