簡體   English   中英

使用index.php而不是index.html是不好的做法嗎?

[英]Is it bad practice to use index.php instead of index.html?

我不確定為什么會這樣,但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

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM