我不知道为什么会这样,但index.html感觉“正确”。我使用index.php是因为如果我的登录失败,我想返回到index.php并在初始登录页面上显示返回的错误,就像这样......
<?php
if(isset($_GET["loginFailed"])) {
echo ($_GET['reason']);
}
?>
这已被修剪了一点,但“原因”将由 php 破译并显示一个用户友好的错误。
登录错误只是从我的“login.php”返回,内容类似于..
if($row === false) {
die(header("location:index.php?loginFailed=true&reason=usernamenotfound"));
}
这一切都工作正常,但我必须将索引命名为index.php而不是index.html。如果我将其更改为index.html,则 php 部分将被忽略。
我的做法有什么问题吗?是不安全还是什么?
最佳答案
使用index.php
代替index.html
没有问题。它不会影响搜索引擎排名 - 因此您想要更改它的唯一原因是为了美观。
如果您想使用index.html
而不是index.php
,有两种选择:
首先,您可以使用.htaccess重写扩展。将以下行添加到您的 .htaccess,它们会将 .html 页面的所有请求重新映射到 .php 页面,而不更改 URL。
RewriteEngine on
RewriteRule ^(.*)\.html$ $1.php [nc]
其次,您可以允许 PHP 解释器解析 .html 文件。为此,请将以下行添加到您的 .htaccess 中(不同的主机有不同的语法,第一行适用于大多数共享主机)
AddHandler application/x-httpd-php5 .html .htm
AddType application/x-httpd-php .html .htm
AddHandler application/x-httpd-php .html .htm
关于php - 使用index.php而不是index.html是不好的做法吗?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36625170/